Created
April 24, 2020 21:02
-
-
Save ZhouYang1993/d1fc933d70805386fc4383245e85a90e to your computer and use it in GitHub Desktop.
File Handling in Python
This file contains hidden or 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
| # 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