[Tutor] Single Backslash (was 'DOS Commands?')

Magnus Lycka magnus@thinkware.se
Mon Nov 11 08:23:02 2002


Hi James!

There's a tiny bug left. Hope it'll work once that's
fixed.

At 11:09 2002-11-11 +0000, James.Rocks@equant.com wrote:
>      popen(sDOSCommand, 'w').readlines()

This should be
       popen(sDOSCommand).readlines()

Just skip the 'w'. You *read* from the file descriptor,
right? So why do you open it with 'w'?

The 'w', 'r' flags have nothing to do with the
content of your "DOS" command if that's what you
think. They have everything to do with how you
use the file descriptor in Python. This one you
read from with the readlines() method. That means
you must use 'r' (which is the default).

See:
 >>> print os.popen('dir', 'w').read()
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
IOError: [Errno 9] Bad file descriptor
 >>> print os.popen('dir').read()
.........


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se