newbie question - executing system commands

Andy Todd andy_todd at
Tue Sep 4 14:32:04 CEST 2001

"Borzoj" <borzoj at> wrote in
<9n23h1$qsc$1 at>: 

>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
>...or in other words what is the easiest way to execute shell
>command/external program from python and
>get access to it's output?
>This will be your new motto: dance like it hurts, love like you need
>money, work when pepole are watching.

Look at the documentation for the module 'os' -

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