Learning python - read files created

# # Read files created
# file exists? does not exist? The operating system
# read write read r W Write
# open a file
# FS = Open ( "xiaojian.txt", encoding = "UTF-. 8")
# Print (FS)

# Read
# person_info = fs.read () # n Specifies the number of bytes read default, all read out.
Print # (person_info)
# Print ( "======================")
# Per2 = fs.read ()
# Print (Per2)

# # 按行读取
# line1 = fs.readline()
# print(line1)
# print("************************")
# line2 = fs.readline()
# print(line2)
# print("**********************")
# line3 = fs.readline(3)
# print(line3)

Write # w
# wrap the Write not take the initiative. You need to add \ n to wrap.
# If the file exists, the original content is overwritten. If the file does not exist, the file is created.
Open FS = # ( "movies.txt", "w", encoding = "UTF-8")
# fs.write ( "My favorite movies are: The Avengers 4. \ n") # write
# fs.write ( "I like the anime are: fighting broke sky \ n I like the class are:. class17 \ n")
# # fs.write ( "I like the class are: class17")
# # write multi-line argument is a list nor is it will automatically wrap. You need to add \ n to wrap.
# # Fs.writelines ([ "I am a ruby \ n", "I was on the road \ n", "I like to eat meat \ the n-"])
# fs.Close () # close the file

Append # A
# If the file does not exist, then create additional write. If present, the content of the file append
FS = Open ( "D: \\ Pychram-Workspace \\ \\ movies.txt class_20190420 python17 \\", "A", encoding = "UTF-. 8")
fs.write ( "\ n I'm ready to see the Avengers on a holiday, the students do not spoilers !!")
fs.read ()
fs.Close () # close.

# To finish, close the file. Then open the file to read.
File #: external resources. OOO.

# Exception.

 

Guess you like

Origin www.cnblogs.com/qsmyjz/p/11261227.html