Suggestions for good programming practices?

Peter Hansen peter at engcorp.com
Sun Jun 23 22:46:45 EDT 2002


Dianne van Dulken wrote:
> 
> I'm fairly new to python, coming from a perl background, and was wondering
> if anyone has a list of things that they consider as good programming
> practice in Python (I thought this might be an interesting topic for
> discussion, anyway)
> 
> For example, in perl you obviously are always encouraged to use strict, and
> we always use eval around our main code to pick up any unexpected errors.  I
> presume the equivalent in python is the try statement.  Would you suggest
> that this should be used, or would that be redundant here?  Any other tips
> that you would suggest a new python user should be always doing as a good
> programming practice?

While it's not quite an answer to the question you asked, you should
read this:

  http://www.python.org/doc/essays/styleguide.html

I would say in addition to that, that unlike many other languages you
don't need to worry too much about other good programming practices
if you just write simple, clean Python code.  Make your goal to 
write the most readable and maintainable code you can, and all else
will follow.

As for try/except... if you want you could put a non-specific 
try/except around the entire application, but all that would be good
for is to mask fatal errors and prevent the interpreter from printing
them properly to show you what went wrong.  Not sure why you'd want
to do that in smaller programs at all, though in large ones you might 
catch the exceptions and write them to an error file for later analysis.

-Peter



More information about the Python-list mailing list