Python equivalent to @lines = 'command';

Christer Frovik 013-139047 at telia.com
Tue Dec 18 17:55:24 EST 2001


Tim Hammerquist wrote:

> Not familiar with PERL, but I'm quite familiar with Perl.
>
> You seem to be looking to pipe a command's output to a variable
> (which is all Perl's backticks really do). Look at the os.popen family
> of functions, in this case, os.popen()
> 
>     import os
>     lines = os.popen('ls -1').readlines()
>     for line in lines:
>         process(line)

Thanks, you've made my day.

I wish those pyTHON (giggle) tutorials would include more of 
these 'neat recepies'.

/CF



More information about the Python-list mailing list