stdout to file

Sposhua NULL at my.pc
Fri Dec 10 05:54:34 EST 1999


Right, useless newbie question here...

Is there any point to using:

file = open("inquisition.txt","w")
file.write("Nobody expected it.\n")
file.close()

...when this seems more efficient and closer to the shell:

import sys
sys.stout = open("inquisition.txt","w")
print "Nobody expected it.\n"

Are there occasions to use one instead of the other? Is #2 really more
efficient?

Also, in #2, do you have to "close" stdout (and if so how,
sys.stout.close()?) and how do you reset stdout to the screen (.close()
again?).

Cheers

PS, I'm sending this in Outlook, which I don't know very well. Does it look
ok in Pine and other text-only mailers? Do the lines wrap at 70(ish)
characters?






More information about the Python-list mailing list