[Pythonmac-SIG] Printing to a file

Robin B. Lake rbl@hal.cwru.edu
Sat, 20 May 2000 12:46:47 -0400 (EDT)


Mac G3, OS 8.6, Python 1.6a1.

I'm reading HTML pages off the Web and trying to file the contents
of each page into a Mac file.  I create the new file with a name
derived from a line found on each Web page (no problem).  I'm then
setting stdout to that file and printing the downloaded page:

	sys.stdout = fpout 
	<SNIP>
	this = urllib.urlopen('http://spamframjam/sub1/sub2/page',parameters)
	print this.read()

later, at the bottom of the inner loop, I do:

	fpout.close()

Problems:  Sometimes I can create the 25 files created in the inner loop,
sometimes it hangs.

What I'd LIKE to be able to do is either copy the "this" instance above
into the file created and pointed to by fpout.  copyfile(this,fpout) does
not work.  Doing it that way would not tie up stdout.  

Also, the 
fpout = open( newpath, 'wb')
<SNIP>
fpout.close()

pair just might be out of sync  --- should I wait for an event on
the fpout.close() before proceeding?

BTW, this is based on an AppleScript that works, but certain aspects
of the Python URLlib are different from WebMiner's:
open url  posting {param,value} approach.  Haven't figured it all out
yet.

Thanks,
Rob Lake
rbl@hal.cwru.edu