Created
September 22, 2018 14:28
-
-
Save pknowledge/9ae8d0621b0932a996f8a36333fe9566 to your computer and use it in GitHub Desktop.
Python Tutorial for Beginners 41 - Create a Text File and Write in It Using Python. https://youtu.be/walXPsausPI
This file contains 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 --------------- | |
fh = open('demo.txt', 'w') | |
try: | |
for i in range(10): | |
fh.write("this is line no %d\n" % (i+1)) | |
finally: | |
fh.close() | |
# Example 2 --------------------- | |
with open('C:\\files\\demo2.txt', 'w+') as fh: | |
for i in range(10): | |
fh.write("this is line no %d\n" % (i + 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment