The next formal learning python

Manipulate files with python

Step one; locate the file, open the file

Step II; modify a file, read the file

Step three; close the file, and save

With the following code demonstrates;

 

Open F = 1. (File NAMA) 
2. reached, f.read (read byte #) # do not write all the read default write method f.write (Data)
3.f.close # close and save the
read real column;
f = open(file = 'C:\\Users\\Public\\heloo',mode="w",encoding='utf-8')
f.write('欢迎\n')
f.write('xiaoma\n')
f.close()
写入实例;
Open = F (File = 'C: Public \\ \\ \\ heloo the Users', MODE = 'R & lt', encoding = 'UTF-. 8') 
Print (reached, f.read ())
f.close ()
# Notes windows next to the file path to \\ separated by a space can not be
The following is a practice used · can not see
'' 'In python action file 
1. file, open
2, read, modify,
3 or turn off to save
code demonstrates
1. F = Open (File NAMA)
2. reached, f.read (# bytes read) does not write # All default read write f.write (Data)
3.f.close Close and save #
4 only open mode, mode of operation in only one file.
R & lt read read
w write directly cover has created
a append file from adding rearmost

F = Open (File = 'C: Public \\ \\ \\ heloo the Users', MODE = "W")
f.write ( 'welcome \ n-')
f.write ( 'xiaoma \ n-')
F .close ()
F = Open (File = 'C: Public \\ \\ \\ mm the Users', MODE =' W ')
f.write (' xiaoma 12345678901 \ n-')
Print (' ------ delimiter ---------- ----------- ')
f.close ()
F = Open (File =' C: Public \\ \\ \\ mm the Users', = MODE 'R & lt')
Test = F.readline () # read line
Print (Test)
Print ( '--------')
f.close ()
f = open(file = 'C:\\Users\\马东\\PycharmProjects\\hihi.py',mode = 'w')
f.write('heloo world')
f.close()
f = open(file = 'C:\\Users\\马东\\PycharmProjects\\hihi.py',mode="r")
print(f.read())
f.close()
f = open(file = 'C:\\Users\\马东\\PycharmProjects\\www',mode='w',encoding = 'utf-8')
f.write('小马你好呀!')
f.close()'''
f = open(file = 'www',mode='r',encoding='utf-8')
print(f.read())
f.close()



 

 

 

Guess you like

Origin www.cnblogs.com/xiaolang666/p/11852925.html
Recommended