Best Practices for Python Script Development?

metaperl metaperl at gmail.com
Thu Aug 24 22:04:41 EDT 2006


Hello, I am responsible for converting 30 loosey-goosey Perl scripts
into 30 well-documented easy to understand and use Python scripts.

No one has said anything in particular about how this should be done,
but the end product should be "professional" looking.

So, I'm looking for some books and suggestions which will help me write
high-quality scripts. I know about object-oriented programming and
application configuration and have spent 6 years doing professional
Perl but have decided that Python is the new choice of serious agile
developers. Only thing is, I only figured that out 1 month ago and
don't really know how to write good code yet :)


Documentation
=============
I would like browseable HTML documentation for each script. I have
started
to get some idea of using docstrings within a file and that they can
be extracted but would like a pointer to some docs on this practice.

`Pydoc <http://docs.python.org/lib/module-pydoc.html>`_ seems to be
built around modules and I want to document scripts.

Configuration
==========
Based on `this thread
<http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ce17e8060ac708c?tvc=1&q=ConfigParser>`__
I plan to use ConfigParser to squirrel away generic information like
database connection info. The chapter "table-driven code" in Bruce
Eckels' "Thinking in Python" seems like it would've been of help but
it is not written. Any weblinks for similar articles?

The directory hierarchy is going to be /data/vendor/X where X is a
particular data vendor. In /data/vendor/config.ini will be the generic
config info along with an index.html giving an overview of the whole
shebang.

Usage
=====
Most scripts will be run from cron and so should be driveable via
command-line options.

optparse looks very good to me. And I had never thought about
required versus optional arguments in the way that it does. What an
eye-opener.

Searching cheeseshop.python.org/pypi for getopt modules does not work
very well by the way.

Version Control
===============
I've been using bazaar but mercurial seems to be quicker to create
forward-facing browseable web repos. And the propagation and pull
facilities seem more integrated and useable. But both are highly
desireable products.

OS X
====
I'm doing all this on OS X. I like Unix but am too dumb for Linux.
Windows is a great GUI but I hate the registry and hate jumping back
and forth between Windows and Cygwin and never getting the full power
of either.

I think I'll get 2 Mac Minis - one for the
actual data munging and one to back everything up on.

Which actual Python distro I will use is going to be based on the data
I get from `this thread
<http://groups.google.com/group/comp.lang.python/browse_thread/thread/5c4cde4206d1fbb7/f844fa418e8171dc#f844fa418e8171dc>`_

Books
=====
I think these 4 will carry me a long way, but any other suggestions ar
welcome:
* `Dive into Python <http://diveintopython.org/toc/index.html>`_
* `Text Processing in Python <http://gnosis.cx/TPiP/>`_
* Python Cookbook
* Programming Python




More information about the Python-list mailing list