Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

0
votes
0answers
9 views

How to handle returned value if an exception happens in a library code

There is a lib code, trying to parse an Element Tree object. If exception happens, it either returns an empty dict of dict or a partially constructed object of such type. In this case, caller needs to ...
4
votes
2answers
108 views

How can I memoize or otherwise optimize this code?

The code checks many more conditions like the one below. I was thinking to memoize it, but I can't think about how (writers block). How else could I optimize this? I know it seems silly, but my code ...
2
votes
1answer
30 views

Parsing XML with double nested tags using mindom

I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated. # This is only part of XML that interesting me: # ...
6
votes
2answers
81 views

python: design of a simple game

I am trying to code Battleship. It should be a text one-player game against computer where computer and human player take turns in shooting at opponent's ships. I decided to start implementation with ...
2
votes
3answers
119 views

Writing beautiful and efficient code in python - how can I improve this code?

I have often read about how important clear and efficient code is. Also often people talk and write about 'beautiful' code. Some hints and critic from experienced developers for the following code ...
4
votes
2answers
96 views

Python line condenser function

This is a function I just wrote that tries to condense a set of strings into grouped lines. It actually works, but looks ugly. Is there a better way to achieve the same thing? Take 4 filtering empty ...
2
votes
3answers
65 views

Set a default if key not in a dictionary, *or* value is None

Let's say I have a key 'messages' that is usually a list, but might be None, or might not be present. So these are all valid inputs: { 'date': 'tuesday', 'messages': None, } { 'date': ...
0
votes
1answer
54 views

Is there a better way to make a function silent on need?

I got a piece of code I'm not pleased with; Does anyone would have a better idea? def myFunc(verbose=True): if not verbose: print = functools.partial(globals()['print'], ...
6
votes
2answers
189 views

Speed up solution to Project Euler problem 75

I've been programming for a few months now, and have used Stack Overflow a great deal, but this is my first post. Anyway, I wrote this code for Project Euler problem 75, and was curious if anyone knew ...
1
vote
1answer
37 views

Improve file-path finding method

I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: {'Tkinter.py': 'C:\Python27\Lib\lib-tk\Tkinter.py', ...}. I am using this in a ...
1
vote
1answer
46 views

Python - get tuple of the first and last days of the last N months

I am trying to get a tuple of date (or datetime) objects over the last N months. My thought was to use the dateutil package with something like this: def last_n_months(n=12, ending=None): ...
2
votes
1answer
88 views

Is there a better way to code this text adventure game? (python)

This is my first attempt with a basic text adventure game, and i was wondering if there was a way to make it more efficient, or any other things i could add to make the game better.. It isn't totally ...
0
votes
2answers
59 views

Python: Modularized Programming to find Circumference, Diameter, and Area from circles Radius

I have to create a modularized program that can find out the Diameter, Circumference, and Area of a circles radius. I'm sure many of you can notice I kind of winged this from a example given from my ...
-1
votes
0answers
34 views

Blurring an image using python [closed]

I need to blur an image by taking a kernel K and averaging the values in the 2D array and setting the center value to the average of K. Here is the code I have written to do so... def Clamp(pix): ...
2
votes
0answers
23 views

Accelerate OpenGL 2d on python3

I used OpenGL to draw about 20 circles. Each circle has 2 lines, ~10 segments, and all of them have different colors and lenght. FPS ~=4. How can I do this faster? I am using Python 3 on Ubuntu Sorry ...

1 2 3 4 5 52
15 30 50 per page