0

hello why don't print text? (python) output:[] [] []

import names if __name__=="__main__": txt1=open("1.txt","w+") for i in range(0,3): txt1.write("%s\n" % names.get_first_name()) txt2=open("2.txt","w+") for i in range(0,3): txt2.write("%s\n" % names.get_first_name()) txt3=open("3.txt","w+") for i in range(0,3): txt3.write("%s\n" % names.get_first_name()) print(txt1.readlines(),txt2.readlines(),txt3.readlines())

6th Jan 2019, 2:10 PM
kokito
2 Respuestas
+ 4
When changing from writing to a file to reading from the same file, use seek(0) to jump back to the beginning of the file. Also, make sure to close all those files to prevent data loss. It's better to use context managers when dealing with files: with open('file.txt', 'w+') as file: # do something # file is closed automatically
7th Jan 2019, 5:46 AM
Anna
Anna - avatar
+ 3
write("%s\n, yourstring) The separator of arguments to a function is comma (,) not %
6th Jan 2019, 3:52 PM
Gordon
Gordon - avatar