Jan Lamb learned, Wu Pei Qi told Day18-4 file operations

print (data.decode ( 'utf-8 ')) utf-8 format conversion 
f.write ( 'Young member' .encode ( 'utf-8' )) is converted to bytes
# f.write (bytes ( '1111 \ n- ', encoding =' utf-8 ')) is converted to bytes

F = Open (' b.txt ',' R & lt + ', encoding =' Latin-. 1 '). 1-coding Latin most compatible encoding formats, and support only numeric letters

f.flush () flashed file
print (f.tell ()) of the current position of the cursor
f = open ( 'b.txt', 'r', encoding = 'utf-8', newline = '') # read take the real file line breaks
f.seek (3,1) to move the cursor forward position 3 1 is a front current 3 is the last 2
read () to read a 3 bytes (one character) 
f.truncate (10) the first 10 bytes of the file taken overwrite the original file and save

Guess you like

Origin www.cnblogs.com/gxrwsb/p/11574937.html