Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created April 24, 2020 21:02
Show Gist options
  • Save ZhouYang1993/d1fc933d70805386fc4383245e85a90e to your computer and use it in GitHub Desktop.
Save ZhouYang1993/d1fc933d70805386fc4383245e85a90e to your computer and use it in GitHub Desktop.
File Handling in Python
# Example 1
with open('test1.txt', 'w') as f:
f.writelines(["1", "2", "3"])
# The contents of test1.txt is:
# 123
# Example 2
with open('test2.txt', 'w') as f:
f.writelines(["1\n", "2\n", "3\n"])
# The contents of test2.txt is:
# 1
# 2
# 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment