Python, Repl.it - Details Are Not Being Written To File Using Csv.writer And Writer.writerow
I have the following repl.it program, and note that the registration part of the program, that was working fine before, has stopped working. It gets to the end where it says 'writt
Solution 1:
You're attempting to read a file that's still open:
defregister():
# ...withopen("dating.txt","a") as fo:
# ...print("written to file")
# At this point, "dating.txt" hasn't been written to# the next call to open it that occurs here will# see the state of the file either partially written, or before# the row is written at all
mainmenu()
There are a few solutions. The quickest is to de-indent mainmenu()
here one level:
defregister():
# ...withopen("dating.txt","a") as fo:
# ...print("written to file")
# dating.txt has been closed now, it's safe to read it
mainmenu()
When the next method comes along and tries to read the file, it will contain the expected data that way.
Solution 2:
I may be wrong, but do you need writerows
instead of writerow
because writerows
accepts a list just as yours and writerow
accepts columns.
Post a Comment for "Python, Repl.it - Details Are Not Being Written To File Using Csv.writer And Writer.writerow"