ISO exemplary Python scripts

K

kj

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
 
K

kj

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
 
R

Rhodri James

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top