python

Trailing slashes in Pylons Routes

What is the best way to make trailing slashes not matter in the latest version of Routes (1.10)? I currently am using the clearly non-DRY: map.connect('/logs/', controller='logs', action='logs') map.connect('/logs', controller='logs', action='logs') I think that turning minimization on would do the trick, but am under the impression t...

how do I implement a custom code page used by a serial device so I can convert text to it in Python ?

I have a scrolling LED sign that takes messages in either ASCII or (using some specific code) characters from a custom code page. For example, the euro sign should be sent as <U00> and ä is <U64> (You can find the full code page in the documentation) My question is, what is the most pythonic way to implement this custom code page...

Environment Variables in Python on Linux

Python's access to environment variables does not accurately reflect the operating system's view of the processes environment. os.getenv and os.environ do not function as expected in particular cases. Is there a way to properly get the running process' environment? To demonstrate what I mean, take the two roughly equivalent programs...

Are there any web based email clients written in python?

I need to integrate a email client in my current python web app. Anything available? L.E.: I'm building my app on top of CherryPy ...

What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass ?

I know most of the ins and outs of Python's approach to private variables/members/functions/... However, I can't make my mind up on how to distinguish between methods for external use or subclassing use. Consider the following example: class EventMixin(object): def subscribe(self, **kwargs): '''kwargs should be a dict of e...

How can I use Python for large scale development?

I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base? When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it for you, how do you do it in Python? ...

How do I convert any image to a 4-color paletted image using the Python Imaging Library ?

I have a device that supports 4-color graphics (much like CGA in the old days). I wanted to use PIL to read the image and convert it using my 4-color palette (of red, green, yellow, black), but I can't figure out if it's even possible at all. I found some mailing list archive posts that seem to suggest other people have tried to do so ...

Any python libs for parsing Bind config files?

Any python libs for parsing Bind config files? Basically something that will aid in adding/removing zones and records. This needs to work even if someone modifies the config by hand so overwriting the configs every time is not a solution. ...

What are some best practices for large-scale development in Python?

I don't like the "Is too! Is not!" nature of a lot of the responses that this question provoked. But I'm really interested in some of the answers, and I'd like to hear more about them. So I'm asking the question from a different perspective. It's pretty clear to me, after having built a number of medium-size Python projects by myself...

How to get file creation & modification date/times in Python?

I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows. What's the best cross-platform way to get file creation & modification date/times in Python? ...

Is there a reason Python strings don't have a string length method?

I know that python has a len function that is used to determine the size of a string, but I was wondering why its not a method of the string object. Update Ok, I realized I was embarrassingly mistaken. __len__() is actually a method of a string object. It just seems weird to see object oriented code in Python using the len function on ...

Multiple mouse pointers?

Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow. Is this something I should try to farm out to some other appli...

Any python libs for parsing apache config files?

Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)? As i'll be able to rewrite them in python. ...

How do you programmatically reorder children of an ATFolder subclass?

I have Plone product that uses a custom folder type for containing a set of custom content objects. The folder type was created by subclassing BaseFolder and it has a schema with a couple of text fields. Currently, when custom objects are added to the custom folder, the objects are sorted alphabetically by their id. How can I override...

python properties and inheritance

I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like: class Foo(object): def _get_age(self): return 11 age = property(_get_age) class Bar(Foo): def _get_age(self): return 44 This does not work (subclass bar.age returns 11). I ...

How do I parse a listing of files to get just the filenames in python?

So lets say I'm using Python's ftplib to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) inside a list? See the link above for example output. ...

Daylight savings time change affecting the outcome of saving and loading an icalendar file ?

I have some unit tests that started failing today after a switch in daylight savings time. We're using the iCalendar python module to load and save ics files. The following script is a simplified version of our test. The script works fine in 'summer' and fails in 'winter', as of this morning. The failure can be reproduced by setting ...

Formatting dict.items() for wxPython

I have a text box in wxPython that takes the output of dictionary.items() and displays it to the user as items are added to the dictionary. However, the raw data is very ugly, looking like [(u'BC',45) (u'CHM',25) (u'CPM',30)] I know dictionary.items() is a list of tuples, but I can't seem to figure out how to make a nice format that ...

Refactoring "to hit" values for a game

I'm making a game and one of the methods calculates a character's base hit numbers based on skill values. The method currently calculates each value individually, since each skill can be used at short, medium, and long range. I originally thought I could combine the skills into a tuple and iterate over it, dynamically creating each hit ...

How do you log server errors on django sites

So, when playing with the development I can just set settings.DEBUG to True and if an error occures I can see it nicely formatted, with good stack trace and request information. But on kind of production site I'd rather use DEBUG=False and show visitors some standard error 500 page with information that I'm working on fixing this bug at...