Python fourteenth day

25 February 2020
File
1, File Open: open ( 'file location', mode = 'reading way', enconding = 'decoding mode', Buffering = 1)
1) is equal to 0 Buffering off, equal to one turn.
2) beffering greater than 1, the custom buffer size.
2, pattern mode = "w"
NOTE :
W: opened for writing,
A: Open the append mode (from EOF start, creates a new file if necessary)
R & lt +: opened in read-write mode
w +: opened in read-write mode (see W)
A +: open (see a) write mode
rb: open binary read mode
wb: binary opened in write mode (see W)
ab &: open binary append mode (see a)
RB +: opened in binary read-write mode (see R & lt +)
WB +: opened in binary read-write mode (see W +)
ab & +: opened in binary read-write mode (refer to A +)
. 3, the file is closed f.close ()
with the automatic release of resource blocks
close () closes the file
with open ( ) as variables: automatic release resources
utf-8 (accounting for 3bit), gbk (accounting for 2bit), gb2312 (accounting for 2bit), ascii (accounting for 1bit)
4, write: f.write ( "\ n Hello")
5, read
Print # (reached, f.read ())
# Print (f.readline (2))
# Print (f.readlines ())
Note :
reached, f.read () # read, can choose to read the size parameter
f. feadline () # read each line, the parameters can be read on behalf of his party several characters
f.readline () # once read multiple lines, the equivalent of an iterator parameter indicates read a few lines
f.write () # write to f in
f.writeline () # can put a list of tuples, iterative write

Published 13 original articles · won praise 0 · Views 275

Guess you like

Origin blog.csdn.net/qq_45212418/article/details/104506422