Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created August 28, 2021 18:46
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 kyanny/787de7ef15eaf7f414d36ac35dedacb2 to your computer and use it in GitHub Desktop.
Save kyanny/787de7ef15eaf7f414d36ac35dedacb2 to your computer and use it in GitHub Desktop.
import tempfile
with tempfile.NamedTemporaryFile() as tmp:
print(tmp.name)
tmp.write(b'Hello\nWorld')
tmp.seek(0)
with open(tmp.name) as f:
print(f.read())
with tempfile.NamedTemporaryFile(mode='w+t') as tmp:
print(tmp.name)
tmp.write('Hello\nWorld')
tmp.seek(0)
with open(tmp.name) as f:
print(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment