Alright, I give up...chalk this one up to experience...

Charles G Waldman cgw at fnal.gov
Tue Nov 16 13:14:32 CET 1999


Endgamer writes:

> I can't see why, when I run this as a script from Windows 95, it
> doesn't return the current date setting on my machine.
>
> # Date setting program (chunk 1)
> import os
> 
> olddate=os.popen("date",'r')
> olddate=readdate
> print olddate
> 


What is "readdate"?  I'd expect this snippet of code to give a
NameError since readdate isn't defined anywhere.  I'm not quite sure
what your intention is here, with the line "olddate=readdate"; what's
the point of calling the popen function and assigning the returned
value to olddate if on the very next line you're going to throw this
value away (by reassigning to olddate), before doing anything with it?

I think the info that you need to know is this: os.popen returns a
file-like object from which you can read the output of the executed
command.  You use it like this:

import os
pipe = os.popen("date",'r')
olddate = pipe.read()
exit_status = pipe.close()
print olddate





More information about the Python-list mailing list