Best Practices for Python Script Development?

Discussion in 'Python' started by metaperl, Aug 25, 2006.

  1. metaperl

    metaperl Guest

    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
     
    metaperl, Aug 25, 2006
    #1
    1. Advertising

  2. metaperl

    Robert Kern Guest

    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
     
    Robert Kern, Aug 25, 2006
    #2
    1. Advertising

  3. Richard Jones, Aug 25, 2006
    #3
  4. metaperl <> wrote:
    > 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 <> -- http://www.craig-wood.com/nick
     
    Nick Craig-Wood, Aug 25, 2006
    #4
  5. metaperl

    Ant Guest

    > `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).
     
    Ant, Aug 25, 2006
    #5
  6. metaperl

    Guest


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


    Ant> Any python script *is* a python module. So pydoc is what you are
    Ant> after here.

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

    Skip
     
    , Aug 25, 2006
    #6
  7. metaperl

    metaperl Guest

    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.
     
    metaperl, Aug 30, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer
    Replies:
    2
    Views:
    469
    John Saunders
    Aug 6, 2003
  2. Amelyan
    Replies:
    2
    Views:
    499
    Steve C. Orr [MVP, MCSD]
    Apr 30, 2005
  3. Kevin Frey

    Best Practices for Web App Development ?

    Kevin Frey, Feb 3, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    495
    Raymond
    Feb 3, 2006
  4. Pablo

    Development best practices

    Pablo, Oct 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    357
    Cowboy \(Gregory A. Beamer\)
    Oct 4, 2006
  5. Flavio
    Replies:
    8
    Views:
    313
    Flavio
    Feb 22, 2007
Loading...

Share This Page