+ 1
why am I getting a no output on file read and right option
I don't know where I went wrong file = ("a.txt","w+") file.write ("hello world") cont = file.read() print(cont) file.close()
5 Réponses
+ 1
Ah, fair point. After the write operation the file cursor is at the end of the file, which means that tge read is essentially reading from the end of the file till the end of the file ... Try moving the cursor to the beginning of the file before the read operation: file.seek(0)
0
Remember to open / create the file: file = open("a.txt", "w+")
0
file = open("a.txt","w+")
file.write ("helloworld")
cont = file.read()
print (cont)
file.close
0
still no output
0
that solved it it didn't go over that