python open early learning function

open ( "path", "Open") Open: 'r' read-only mode, 'w' write mode, 'a' append mode 'b' binary mode '+' read / write mode.
example:

fh = open ( "F: /file1.txt", "w") # to write open the file, if the file exists on open, if the file does not exist then create open (the file has been opened in write mode when the original will some content replaced, so either replace, then use append mode)

fh1 = open ( "F: /file2.txt", "r") # to open the file for reading

Example:

Open = FH ( "D: /file1.txt", "W")
contents1 = "This is a content file"
fh.write (contents1)
fh.close ()

D written to the disk file file1.txt "This is the content of the file" file1.txt file if you create the file does not exist then write content

 

fh2=open("d:/file2.txt","r")
data2=fh2.read()
print(data2)

D read the contents of the disk file file2.txt

Guess you like

Origin www.cnblogs.com/tinglele527/p/11541491.html