Python MOOC question In Chapter 11 of (How to Think Like a Computer Scientist) there are some examples given. >>> newtext=open("test2.dat", "r") >>> print newtext.read() Now is the timeto close the file >>> print newtext.read() The second time I use print newtext.read() it gives me no results. I have no Idea why this is, I've stored the contents of the file "test2.dat" in the variable newtext, right? Any ideas?
newtext is a file object. It allows various operations (methods) to be called. The contents of the file haven't been stored. They were printed. My guess is that since you read the file, the file's pointer is pointing to the end of the file (EOF), and the second call has nothing new to read.
Thank you for your help. :)
Join our real-time social learning platform and learn together with your friends!