(Aug-29-2017, 08:40 PM)jobemorgan Wrote: I am trying to create a program where the code asks questions and puts it into a text file. Is there any errors here or am I missing something out
f = open("test.txt","r+")
print (f.write("hello"))
print (f.read())
Yes.
1) You don't close the file. Other people have been suggesting the with block, because it'll handle closing resources automatically.
2) You never ask questions.
3) You never get the responses to the questions you never ask :p
4) You ignore the responses you never get, and instead always write "hello".
5) You're reading and writing from the same file, without seek()ing. I'm not actually sure what
print(f.read())
does here, since you're already at the end of the file.