os.popen and place in file

Erno Kuusela erno-news at erno.iki.fi
Wed Jun 5 12:04:49 EDT 2002


In article <3CFE2762.519E4344 at motorola.com>, Stephen Boulet
<stephen.boulet at motorola.com> writes:

| I'm running windows NT.
| The command: 
|   f = os.popen('dir')
| returns a file object 'f'. I can't however use the seek command on it [...]
| Anyone know why?

it is because the text output by the "dir" program is relayed directly
to your program. the operating system does not store it away anywhere
in case you want to revisit parts of it later. sockets and many
unix device files work the same way. otherwise there would
be problems when transferring large amounts of data through
pipes.

if you want to access the data like a regular file, you could redirect
the output from the command to a disk file and open that. or, read
all of the data from the pipe and put it in a StringIO object.

  -- erno



More information about the Python-list mailing list