HomeToolsAbout

Files

Read File

r reads a file, errors if the file does not exist

f = open("file_name.txt", "r") print(f.read())

Create New File

x creates a file, returns error when the file exists

a appends to a file, will create a file if the file does not exist

w writes to a file, will create a file if the file does not exist

f = open("file_name.txt", "x") f = open("file_name.txt", "a") f = open("file_name.txt", "w")

Write to File

a appends to the end of the file w overwrites all existing content

f = open("file_name.txt", "a") f.write("override existing content") f.close()
AboutContact