One, character encoding
(1) basic computer Knowledge
(2) How the Python interpreter executes the py file
<1>python Interpreter Launcher
The <2>python interpreter is equivalent to a text editor that opens the txt.py file and reads the contents of the txt.py file from the hard disk into memory
The <3>python interpreter interprets the code that was just loaded into memory txt.py (in that phase and execution, only the Python syntax is recognized, execution of the file memory code, execution to Name= "Egon", will open up memory space to hold the string "Egon")
(3) Similarities and differences between Python interpreter and text editor
the same point: The Python interpreter interprets the execution file contents, so the Python interpreter has the ability to read the Py file, which is the same as the text editor
Different points: The text editor reads the text content into memory for display, and the Python interpreter reads the contents into memory for execution.
Second, what is character encoding
The history of character coding
(1) The computer originated in the United Kingdom, the earliest birth was also based on the English-language considerations ASCII
ASCII: A bytes represents one character (English characters/all other characters on the keyboard), 1bytes=8bit,8bit can represent 0-2**8-1 variations, which can represent 256 characters
(2) In order to satisfy Chinese, the Chinese have developed gkb
Gbk:2bytes represents a character
(3) countries have national standards, there will inevitably be conflicts, the result is that in multi-language mixed text, the display will be garbled.
The resulting Unicode, unified 2Bytes for a character, 2**16-1=65535, can represent more than 60,000 characters, thus compatible with the universal language
Iv. Processing of documents
<1> File Open mode
The mode of opening the file is:
- R, read-only mode "default mode, file must exist, not present, throw exception"
- W, write-only mode "unreadable; not exist" created; empty content "
- X, write-only mode "unreadable; not present, create, present error"
- A, append mode "readable; not present, create; append content only"
"+" means you can read and write a file at the same time
- r+, read and write "readable, writable"
- w+, write "readable, writable"
- x+, write "readable, writable"
- A +, write "readable, writable"
"B" means to operate in bytes
- RB or R+b
- WB or W+b
- XB or W+b
- AB or A+b
Python-based character encoding and file processing