close contact with computer

1. The b parameter is added to open, which can directly manipulate bytes or binary instructions, so as to be suitable for cross-platform or all file operations

2. The default gbk format of windows, unless you decode it into the platform format (a.decode('utf-8')), it will not be garbled during reading

3. The carriage return in windows is \r\n two bytes

4. When writing documents, you need to use the following formats to encode into computer language:

a=open( ' Test 1.1 ' , ' wb ' )
b=a.write(bytes('11111\n',encoding='utf-8'))
b =a.write( ' My grass'.encode( ' utf-8 ' ) )
a.close()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325640725&siteId=291194637