Perform IO with Text Files

From rbachwiki
Revision as of 22:54, 5 January 2019 by Bacchas (talk | contribs) (Created page with "==Opening a File== myfile= open('filename.txt') myfile.read() # reads a string of everything in the file myfile.seek(0) # reset the cursor to the top of the file contents...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Opening a File

myfile= open('filename.txt')
myfile.read() # reads a string of everything in the file
myfile.seek(0) # reset the cursor to the top of the file
contents = myfile.read()
myfile.readlines() # will read lines as a list
myfile.close() # closes the file
with open('filename.txt') as my_new_file:
 contents = my_new_file.read()
==File Locations==