473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
6 5344
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Woody | last post by:
I am looking for some examples of how to manage DDL scripts among various versions of a production db and development and testing. I have tried a few things in the past, and it always gets very...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
217
by: gyromagnetic | last post by:
The following url points to an article written by Damian Conway entitled "Ten Essential Development Practices": http://www.perl.com/pub/a/2005/07/14/bestpractices.html Althought the article has...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
4
by: Collin Peters | last post by:
I have searched the Internet... but haven't found much relating to this. I am wondering on what the best practices are for migrating a developmemnt database to a release database. Here is the...
1
by: Pablo | last post by:
Hello all, Hope today finds you well. I'm looking to take my knowledge of best practices within the development lifecycle to the next level. Basically I want to follow industry recognised,...
8
by: Flavio | last post by:
Hi, Nowadays the addition of functionality to programs by means of plugins is very frequent. I want to know the opinions of experienced Python developers about the best practices when it...
12
by: Scott Sharkey | last post by:
Hello all, Our development group at work seems to be heading towards adopting python as one of our standard "systems languages" for internal application development (yeah!). One of the issues...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.