Reputation: 304
So I wrote this code and it works perfectly fine on Linux.
Here's the part of the code that is supposed to do that:
outFile = open( "input.txt", "w" )
for item in oplist:
outFile.write(item + "\n")
outFile.close
It works perfectly fine on Linux but on windows in only creates the new output file but doesn't write anything into it.
Please help!
Upvotes: 0
Views: 162
Reputation: 1124768
You are not closing the file; you are merely referring to the close method. Call it:
outFile.close()
Without closing the file buffers won't be flushed until Python exits.
A better way to handle file closing is to use the with
statement:
with open( "input.txt", "w" ) as outFile:
for item in oplist:
outFile.write(item + "\n")
Now the file is closed automatically.
Upvotes: 2