python Basics - file (read, operation, shut down)

First, the use of file

1. Type of file: text files and binary files (in essence, all the files are stored in binary form; form, there are two ways to show all files)

 

Open the text file:

tf.open("f.txt","rt")

print(tf.readline())

tf.close()

Open the file in binary form:

bf=open("f.txt","rb")

print(bf.readline())

bf.close()

 2. Open and close the file

 

 2.1 files open:

 

file path:

 

  Open mode

 

 2.2 file is closed:

 

 Second, read the contents of the file

 

 

 

 

 

 

 

 

 

 

 

 Third, the data is written to the file

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/ShallByeBye/p/12468098.html