newbie question - executing system commands

Andy Todd andy_todd at spam.free.yahoo.com
Tue Sep 4 14:32:04 CEST 2001


"Borzoj" <borzoj at pingu.ii.uj.edu.pl> wrote in
<9n23h1$qsc$1 at news.formus.pl>: 

>I'm newbie both in shell scripting and pyhon so please be kind :)
>What would be the Python equivalent for following shell code:
>
>for IMAGE_NAME in `ls`; do {
>#processing of $IMAGE_NAME
>};done
>
>
>...or in other words what is the easiest way to execute shell
>command/external program from python and
>get access to it's output?
>
>thx
>____________
>This will be your new motto: dance like it hurts, love like you need
>money, work when pepole are watching.
>Dogbert
>
>

Look at the documentation for the module 'os' - 
http://www.python.org/doc/current/lib/module-os.html

To convert your example above into Python, try;

>>> for imageName in os.listdir('.'):
...     print imageName

at the interactive prompt and see what you get.

-- 
Content free posts a speciality



More information about the Python-list mailing list