My first Python program

MRAB python at mrabarnett.plus.com
Tue Oct 12 16:07:13 EDT 2010


On 12/10/2010 20:40, Jonas H. wrote:
> On 10/12/2010 09:14 PM, Seebs wrote:
>> http://github.com/wrpseudo/pseudo/blob/master/makewrappers
>
> Just a few pointers, looks quite good to me for a newbie :)
>
> * Less action in __init__.
> * Use `open` instead of `file` to open a file
> * Have a look at context managers for file handling (avoids doing
> error-prune stuff like __del__)
> * Your `del` in line 464 is useless. A reference will be removed from
> the object bound to the local variable 'source' anyway because of the
> re-assignment.
> * according to common Python style guides you should not use underscores
> in class names.
> * no need for 'r' in `open` calls ('r' is the default mode)
> * `line == ''` can be written more pythonic as `not line`
> * `str.{r,l,}strip` removes '\n\t\r ' by default, no need for an
> argument here (line 440 for example)
> * you might want to pre-compile regular expressions (`re.compile`)

The regex will be cached anyway by the re module so it's not a big
problem.

> * raising `Exception` rather than a subclass of it is uncommon.
>
> Hope that helps :-)
>
> Jonas




More information about the Python-list mailing list