So I was reading over the Python Documentation/Tutorial, specifically I was looking at the Input/Output with files. This is what the tutorial says will return whatevers in the file:
>>> f.readline()'This is the first line of the file.\n'>>> f.readline()'Second line of the file\n'>>> f.readline()''
I put the same thing in my .py and it didn't return any exceptions or issues, but it didn't return any values, either. This is my code:
f = open('test.txt')f.readlines()
Unless I use the variables and a print
, the program will not return anything thats in the file. Heres my files contents:
Hello This Is TestFor Loops In FilesFlying AwayA Bird also FliesWow
Any ideas as to why this isn't working? I think its my interpreter, as I am using SublimeREPL, but it hasn't been doing anything weird before then so I am not too sure. Also, when I try running it in my Python console, it gives me an error, then just closes the console so I can't even see the error. Pretty counter-productive.
Just to clarify, my issue is not the for
loop, the for
loop already worked fine from before. The issue is that f.readlines()
does not return any lines, even though the documentation says it should return the next line. I will take the for
loop out of my code to clarify. Also, sorry if I am mixing up f.readline()
and f.readlines()
, but they both don't work, anyway.