New course! Every coder should learn Generative AI!
Try a free lesson+ 3
To get it run, file.seek() needs an argument = 0. So with:
file.seek(0)
it should work.
+ 1
file.read() method only reads file
print (file.read()) prints content read in file
+ 1
In case of your program, the first file.read() will place the file pointer to the end, because it will consume all characters from the file. So the print(file.read()) that comes afterwards, will always be empty. To re-read the content, you can use file.seek() to position the pointer back to the beginning.