KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using Python 3.3.0, on windows 64bit. I have a text file as shown below: (see bottom for download link at mediafire) hello -data1:blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah -data2:blah blah blah blah blah blah blah blah blah blah blah -data3: Empty -data4: Empty I'm trying to navigate around the file, and thus I use .tell() to figure out what my position is. However, when reading through the lines of the file as shown below, I get a very strange result: f=open("test.txt") while True: a = f.readline() print("{} {}".format(repr(a),f.tell())) if a == "": break The result: 'hello\n' 7 '\n' 9 '-data1:blah blah blah blah blah blah blah blah blah blah blah blah blah blah bl ah blah\n' 18446744073709551714 '\n' 99 '\n' 101 '-data2:blah blah blah blah blah blah blah blah blah blah blah\n' 164 '-data3: Empty\n' 179 '\n' 181 '-data4: Empty' 194 '' 194 What's with the 18446744073709551714 for the 3rd line? Though it looks like an impossible value, f.seek(18446744073709551714) is an acceptable value that apparently does bring me to the end of the 3rd line. Though, I can't seem to figure out why. EDIT: Opening in binary mode gives no problems with tell() : f=open("test.txt","rb") while True: a = f.readline() print("{} {}".format(repr(a),f.tell())) if a == b"": break The result: b'hello\r\n' 7 b'\r\n' 9 b'-data1:blah blah blah blah blah blah blah blah blah blah blah blah blah blah b lah blah\r\n' 97 b'\r\n' 99 b'\r\n' 101 b'-data2:blah blah blah blah blah blah blah blah blah blah blah\r\n' 164 b'-data3: Empty\r\n' 179 b'\r\n' 181 b'-data4: Empty' 194 b'' 194 The test.txt text file is downloadable here, just
Tags (comma-separated)
Save Edits
Cancel