1r for reading
2r+ opens for reading and writing (cannot truncate a file)
3w for writing
4w+ for writing and reading (can truncate a file)
5rb for reading a binary file. The file pointer is placed at the beginning of the file.
6rb+ reading or writing a binary file
7wb+ writing a binary file
8a+ opens for appending
9ab+ Opens a file for both appending and reading in binary. The file pointer is at the end of the file if the file exists. The file opens in the append mode.
10x open for exclusive creation, failing if the file already exists (Python 3)
1# Different modes of text file
2"r" = # Open for reading plain text
3"w" = # Open for writing plain text
4"a" = # Open an existing file for appending plain text
5"rb" = # Open for reading binary data
6"wb" = # Open for writing binary data
1#there are many modes you can open files in. r means read.
2file = open('C:\Users\yourname\files\file.txt','r')
3text = file.read()
4
5#you can write a string to it, too!
6file = open('C:\Users\yourname\files\file.txt','w')
7file.write('This is a typical string')
8
9#don't forget to close it afterwards!
10file.close()