Python equivalent to @lines = 'command';

Kirill Miazine km-list-python at miazine.net
Tue Dec 18 09:20:16 EST 2001


* Christer Frovik <013-139047 at telia.com> [20011218 14:09]:
> Is is possible to spawn a command (any command not just ls) 
> and have all the lines that the command outputs stored in a list?
> 
> In PERL this is done quite nicely in a single statement:
> 
>   @files = `ls -1`;
> 
> and you can then iterate over @files and do whatever you want.
> Any ideas, or should i stick with Perl for my mindless scripts?

import os
files = os.popen("ls -1").readlines()

-- 
Kirill




More information about the Python-list mailing list