Created
October 12, 2017 12:48
-
-
Save tadone/62aad10f0f789ace9eaa0ef669a599a5 to your computer and use it in GitHub Desktop.
Read/Write to/from file
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
# Wrtie to file (w write) | |
f = open('helloworld.txt','w') | |
f.write('hello world') | |
f.close() | |
# Write to BINARY file (wb write binary) | |
f = open('database_file','wb') | |
f.write('hello world') | |
f.close() | |
# Append to file (a append) | |
f = open('helloworld.txt','a') | |
f.write('\n' + 'hello world') | |
f.close() | |
# Open file (r read) | |
f = open('helloworld.txt','r') | |
message = f.read() | |
print(message) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment