473,700 Members | 2,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "profession al" 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.c om/group/comp.lang.pytho n/browse_frm/thread/2ce17e8060ac708 c?tvc=1&q=Confi gParser>`__
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.pyth on.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.c om/group/comp.lang.pytho n/browse_thread/thread/5c4cde4206d1fbb 7/f844fa418e8171d c#f844fa418e817 1dc>`_

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 5370
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.pyth on.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.pyth on.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 "Programmin g 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
3017
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 muddled and cumbersome. I need to be able to build any version of the database from scratch, BUT I also need to maintain an upgrade path from any version to any later version. So it is not enough to just maintain a master build script, but I...
11
9252
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
217
9151
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 Perl as a focus, I thought that some of the general points made might be of interest to the Python community. It would certainly be interesting to put together an analogous version of this article that centers on Python. Best Regards,
136
9388
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
2
1820
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) Group relevant .aspx files into subfolders within your project etc.
4
2620
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 simplest example of my situation (real world would be more complex). Say you have two versions of your application. A release version and a development version. After a month of developing you are ready to release a new version. There have...
1
1655
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, Microsoft approved practices for every aspect of the lifecycle - so planning and architecture, team development, testing procedures, change control and bug-tracking, version control - etc etc. What software to use, which
8
2021
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 comes to developing a plugin system for a Python package. Should plugins be modules in a separate package?
12
3932
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 that's come up is the problem with apt (deb packages) vs eggs, vs virtual environments. We're probably gonna end up using Pylons or TurboGears for web-based apps, and I've recommended virtualenv, but one of the other developers has had some...
0
8714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8958
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7797
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2379
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2021
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.