Skip to content

Instantly share code, notes, and snippets.

@secemp9
Created November 30, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secemp9/53dada081e5b5279d0b19d198a8ab88d to your computer and use it in GitHub Desktop.
Save secemp9/53dada081e5b5279d0b19d198a8ab88d to your computer and use it in GitHub Desktop.
file.tell stuff (3.X)
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