ISO exemplary Python scripts

Discussion in 'Python' started by kj, May 9, 2009.

  1. kj

    kj Guest

    I'm learning python, for the umpteenth time. This time I decided
    to start out by writing Python scripts for everyday tasks. Most
    of these scripts are meant to be used only once or twice, but a
    few of them have become useful enough that I'd like to make them
    a little bit more solid...

    I'd like to learn from well-written Python scripts, with well-structured
    options parsing, good error and help messages, clear organization,
    etc.

    Can someone point me to good examples of Python scripts?

    TIA!

    kynnjo

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
    kj, May 9, 2009
    #1
    1. Advertising

  2. kj

    kj Guest

    In <> Tim Roberts <> writes:

    >kj <> wrote:
    >>
    >>I'm learning python, for the umpteenth time. This time I decided
    >>to start out by writing Python scripts for everyday tasks. Most
    >>of these scripts are meant to be used only once or twice, but a
    >>few of them have become useful enough that I'd like to make them
    >>a little bit more solid...
    >>
    >>I'd like to learn from well-written Python scripts, with well-structured
    >>options parsing, good error and help messages, clear organization,
    >>etc.
    >>
    >>Can someone point me to good examples of Python scripts?


    >The standard library that was installed with your interpreter is one of the
    >best repositories. It contains hundreds of working, well-tested scripts,
    >most of which have the ability to run by themselves.


    Thanks, but the last bit of your post ("...most of which have the
    ability to run by themselves") makes me wonder whether we mean the
    same thing when we talk of "scripts." Can you give me an example
    of a script that *does not* have the ability to run by itself?
    When I use the word "script" I mean, *by definition*, a piece of
    code that has the ability to run by itself.

    I know that in the python world the distinction between a script
    and a (library) module is not so clear-cut, and it is common for
    library modules to have "top-level" stuff (typically test code)
    that gets run if the module is invoked directly from the command
    line. But this is not *really* a script as I understand it, because,
    even though it "runs" directly from the command-line, it lacks the
    typical CLI amenities, such as command-line flags, help messages,
    diagnostic messages that are aimed to the "naive user" (i.e. as
    opposed to the developer), etc. The coding of these "CLI amenities"
    is one of aspects of these "exemplary Python scripts" I'm most
    interested in learning about.

    Anyway, thanks, I'll poke around in the standard library...

    kynn

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
    kj, May 9, 2009
    #2
    1. Advertising

  3. kj

    Rhodri James Guest

    On Sat, 09 May 2009 17:09:38 +0100, kj <> wrote:

    > I know that in the python world the distinction between a script
    > and a (library) module is not so clear-cut, and it is common for
    > library modules to have "top-level" stuff (typically test code)
    > that gets run if the module is invoked directly from the command
    > line. But this is not *really* a script as I understand it, because,
    > even though it "runs" directly from the command-line, it lacks the
    > typical CLI amenities, such as command-line flags, help messages,
    > diagnostic messages that are aimed to the "naive user" (i.e. as
    > opposed to the developer), etc. The coding of these "CLI amenities"
    > is one of aspects of these "exemplary Python scripts" I'm most
    > interested in learning about.


    While I don't entirely agree with your definition of a script,
    for a lot of those CLI amenities "optparse" is your friend.
    Possibly also your enemy if you don't want to do things its way,
    but it does at least make parameter handling in a user-friendly way
    easy.

    --
    Rhodri James *-* Wildebeeste Herder to the Masses
    Rhodri James, May 11, 2009
    #3
    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. Franck DARRAS
    Replies:
    12
    Views:
    620
    Jim Higson
    Aug 23, 2004
  2. Alexei Polkhanov
    Replies:
    11
    Views:
    2,443
  3. cs

    Suggestions for exemplary c99 code

    cs, Sep 3, 2007, in forum: C Programming
    Replies:
    4
    Views:
    376
    CBFalconer
    Sep 4, 2007
  4. TomF
    Replies:
    3
    Views:
    301
  5. TomF

    Django as exemplary design

    TomF, May 3, 2010, in forum: Python
    Replies:
    17
    Views:
    458
    Lawrence D'Oliveiro
    May 13, 2010
Loading...

Share This Page