[Tutor] file I/O

kevin parks kp87@lycos.com
Thu, 12 Jul 2001 04:56:49 +0900


Hi. I am a little confused as to why this hangs when i run it. I am trying to make a script that opens a file for input opens a file for writing and reads in a line from the input and copies it to the created output file. In this case except for  the start here and EOF lines the file should be an exact copy. (the point is that later i an going to do something to each line of text), but i have to get this much working, plus the other business i mentioned on UNIX and Mac paths, but first this, Why does it just hang the interpreter? 

This is in Mac OS 9.bloat Python 2.1 IDE


def finout():

	infilename = raw_input('Enter in file name: ')
	infile = open(infilename, 'r')
	f = open('sys:scripts:foo.txt', 'w')
	f.write("start here\n\n")
	done = 0
	while not done:
		aLine = infile.readline()
		if aLine != " ":
			f.write(aLine + '\n')
		else:
			done = 1
	infile.close()
	f.write("\n\nEOF\n")
	f.close()

if __name__ == '__main__':
	finout()




Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/