You must give write string argument.
print "creating a text file"
# 'w' mode creates new file
with open("write_it.txt", "w") as text_file:
score = 5
name = raw_input("What's your name?: ")
text_file.write("%s, %s" % (score, name))
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
Thanks alot pyTony.
You really helped me out.
By the way, I set the mode for "a" because I wanted to append the score, and as you know "a" also creates a new file.
But thanks alot for the help, now I can finish my whole program.
Just consider that you will be allways addding to file in append mode, so you get 'log file' effect. You never clear it if it exists. Therefore it is more common to update file by reading it fully in, changing information in memory and again writing in 'w' mode to file.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852