Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Created April 8, 2022 11:36
Show Gist options
  • Save pointofpresence/26851fa07326398ac3acdaf6638d01d6 to your computer and use it in GitHub Desktop.
Save pointofpresence/26851fa07326398ac3acdaf6638d01d6 to your computer and use it in GitHub Desktop.
Python print to file
with open('out.txt', 'w') as f:
print('Filename:', filename, file=f) # Python 3.x
print >> f, 'Filename:', filename # Python 2.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment