system exec ?

Alex Martelli aleaxit at yahoo.com
Thu Jul 5 14:32:12 CEST 2001


"alphaZeta" <NOSPAM.hnguyen421 at NOSPAM.hotmail.com> wrote in message
news:9i1npl$160$1 at news.businessobjects.com...
>
> Thanks, I was also planning to use the readlines() method.
    ...
> > a = os.popen("ls -l").read()
> >
> > may be what you want (but you may also prefer to call .readlines()

That's good in most cases, just one further thing: if there
is the possibility that the output of the command is vaster
than will comfortably fit in memory, you may want to import
xreadlines and rather than storing said output in your
memory all at one loop over it line by line:

from xreadlines import xreadlines
for line in xreadlines(os.popen("ls -l")):
    process(line)

Not an issue for ls -l, of course, but some OTHER program
MIGHT be returning gigabytes of text that you have to
process, and in that case doing it sequentially is best.


Alex






More information about the Python-list mailing list