467,083 Members | 1,261 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,083 developers. It's quick & easy.

Best Practices for Python Script Development?

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

Aug 25 '06 #1
  • viewed: 4989
Share:
6 Replies
metaperl wrote:
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.
"Does not work very well" how? Are you just not finding anything?

If so, it's probably because there really aren't any, and they wouldn't be
referred to as "getopt modules." There's the (old) getopt module and the
(preferred) optparse module in the standard library. optparse really does fill
the niche quite thoroughly.

However, if you like, there's the newcomer argparse that tries to improve upon
optparse in several respects:

http://argparse.python-hosting.com/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Aug 25 '06 #2
metaperl wrote:
Searching cheeseshop.python.org/pypi for getopt modules does not work
very well by the way.
http://docs.python.org/lib/module-getopt.html
Richard

Aug 25 '06 #3
metaperl <me******@gmail.comwrote:
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.
I was where you are a couple of years ago!
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>`_
This is an excellent book to bootstrap your way into Python. It is
very good for experienced programmers.
* `Text Processing in Python <http://gnosis.cx/TPiP/>`_
I liked this book. However by the time I read it I'd already read
quite a few Python books so I perhaps didn't get as much out of it as
I should.
* Python Cookbook
Cookbooks don't really lend themselves to general reading, but saying
that I did read this one from cover to cover (the previous edition).
There is lots of interesting stuff in there and you'll learn plenty of
tricks, though Python doesn't have nearly as many tricks as Perl to
learn. If you are looking for something in particular there are many
more recipes in the online cookbook.
* Programming Python
The second edition is a thorough introduction to python 2.1. (Amazon
says there is a 3rd edition due out very soon though covering python
2.5.) The 2nd edition is missing newer features of the language, but
otherwise it is a solid book with lots of good stuff in. The section
on programming with TK is very good too - I keep coming back to that
section.

....

I'd recommend the first and the last from your list to start with,
"Dive into Python" and "Programming Python".

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Aug 25 '06 #4
Ant
`Pydoc <http://docs.python.org/lib/module-pydoc.html>`_ seems to be
built around modules and I want to document scripts.
Any python script *is* a python module. So pydoc is what you are after
here.
Version Control
===============
Subversion and Trac are a very good combination - Trac is a web-based
view of the subversion repository as well as being a wiki and issue
tracker. (Incidentally Trac is written in Python.)
Books
=====
* Python Cookbook
* Programming Python
I've found the Python Pocket reference very useful - I rarely use
anything other than that and the online docs (though I found Python in
a Nutshell and the cookbook very useful early on).

Aug 25 '06 #5
>`Pydoc <http://docs.python.org/lib/module-pydoc.html>`_ seems to be
built around modules and I want to document scripts.
AntAny python script *is* a python module. So pydoc is what you are
Antafter here.

Assuming you name your scripts so that they are importable (e.g. "foobar.py"
instead of "foo-bar.sh").

Skip
Aug 25 '06 #6

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

Any python script *is* a python module. So pydoc is what you are after
here.
Yes, but Lundh's PythonDoc looks good too. I'm inclined to go with
that.

Aug 30 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Woody | last post: by
217 posts views Thread by gyromagnetic@gmail.com | last post: by
1 post views Thread by Pablo | last post: by
8 posts views Thread by Flavio | last post: by
12 posts views Thread by Scott Sharkey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.