Created
November 30, 2022 15:30
-
-
Save secemp9/53dada081e5b5279d0b19d198a8ab88d to your computer and use it in GitHub Desktop.
file.tell stuff (3.X)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("test.txt", "w") as w: | |
w.write(""" | |
this is a test | |
this is another test | |
another test""") | |
with open("test.txt", "rb") as e: # when using a for loop or next/basically going through the file, using file.tell only works with "rb", but if you use "r" with a for loop + file.tell, then an error occur | |
for i in e: | |
print(e.tell()) | |
with open("test.txt", "r") as e: # works since there no for loop/next call | |
print(e.tell()) | |
with open("test.txt", "r") as e: # error here | |
for i in e: | |
print(e.tell()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment