shedtrio.blogg.se

Readwrite com
Readwrite com





readwrite com

Tell() Returns the current contents of the file pointer ( One Chinese two bytes ) Seek( skip ,whence)#whence 0 Calculate from the file header 1 From the current position 2 Calculate from the end of the file Seek Move the file pointer to a new location ( The skipped bytes are one Chinese byte and two Chinese bytes ) At the end of the file, The file pointer ends Writelines Write the contents of the list file=open('b.txt','a')# Additional a- Additional, Create files if they don't exist ( The file pointer is at the beginning of the file ), If the file exists, append. Readlines Treat each line in the text file as an independent string object, And put these objects in the list to returnįile=open('b.txt','a')# Additional a- Additional, Create files if they don't exist ( The file pointer is at the beginning of the file ), If the file exists, append. Readline() Read a line in the text file=open('b.txt','r')# Read the original file If you omit, Read to the end of the file, That is, read all the contents of the file at onceįile=open('b.txt','r')# Read the original file

readwrite com

Read(): Read from file size A byte or character content is returned. + Open the file read-write, Do not use alone, Need to be used with other modes a+ Target_file.write(scr_file.read())# What you read out Write. At the end of the file, The file pointer ends file=open('b.txt','a') #file Object on the corresponding disk b.txt fileī- With 2 Open the file in hexadecimal mode, Do not use alone, It needs to be combined with other patterns rb,wb scr_file=open('a.png','rb')# Read the original file W- write in ( Create without There are just replace ) file=open('b.txt','w',encoding='utf-8') #file Object on the corresponding disk b.txt fileĪ- Additional, Create files if they don't exist ( The file pointer is at the beginning of the file ), If the file exists, append. UTF-8 file=open('b.txt','r',encoding='utf-8') #file Object on the corresponding disk b.txt file Rule of grammar : file《 The created file object 》 =open《 Functions that create objects 》(filename《 Name of the file created or opened 》)įile=open('b.txt','r') #file Object on the corresponding disk b.txt file Operation steps :py To operate the document - Open or create a new file - Read and write files - close resource ( Operation is completed ) py file -> Click on the run - Then run through the interpreter -> The operating system is called when the interpreter is running -> Operate files on disk ( Read and write files on the disk ) How it works : queue fifo Read and write at the same timeįirst we write. Reading and writing of documents -IO operation Input and output You can modify the encoding format #encoding=gbk Modify the formatĭifferent encoding formats determine the storage size of the disk

readwrite com

Therefore Python The default encoding format for files is UTF-8-PY The default storage method for files GB2312( Earliest stage )->GBK( Added text )->GB1803( Simplified Chinese character 、 traditional Chinese character 、 Uyghur Language 、.)( These are compatible with ISO8859-1, Expressing Chinese 、 One byte in English Chinese characters 2 Bytes ) ISO8859-1( compatible ASCII):8 position ,256 Characters

READWRITE COM HOW TO

UTF-8:Unicode How to realize 1-4 A byte represents a character, english 1 Bytes, Chinese characters 3 BytesĪSCII code :7 Who said 1 Characters, It can only mean 128 Characters Unicode:2 Byte representation 1 Characters ( A separate ) py Files are used on disk UTF-8 Storage ( External storage ) Python Our interpreter uses Unicode( Memory ) unicode It is usually a representation in memory

readwrite com

The encoding format of the file is UTF-8 still GBK.







Readwrite com