Newbie: executing a system command from my Python app

Dan M dan at wolf.com
Tue Dec 13 16:31:33 EST 2005


> Few points points:
> 
> 1. Generally: I would try to minimize system calls. They make your code less
>     portable.

Excellent point. In this case the app will never live anywhere other than
one specific FreeBSD machine, but I do appreciate the value of the advice
anyway. Therefore...

> 2. Look into the "shutil" module for recursive
deletion. 
> 3. Use os.path
> to construct paths. Try to avoid, for example,
>     "c:\blah\blah" on dos, '/blah/blah' on unix, etc.

Have done so. Thanks for pointing out the shutils module! I keep finding
more and more excellent modules available. Do we have a Python equivalent
to Perl's CPAN?

> 4. If you only have one argument, you don't need a tuple
> for string formatting. 
> 5. "(dateYest)" is not a tuple anyway--the parentheses are
> superfluous 6. Single item tuples can be created with "(anitem,)"
> (notice the comma).

That helps. I had somehow gotten the mistaken idea that string formatting
always needed a tuple, and overlooked the trailing comma. I've applied
that correction to several of my other Python scripts as well.





More information about the Python-list mailing list