python development [first article]
- Content encoding When the python interpreter loads the .py file, it encodes the content (ascii encoding by default).
ASCII is a computer coding system based on the Latin system. It is mainly used to display modern English and other Western European languages. It can only be represented by 8 bits at most (one byte), namely: 28=256, so ASCII is the most It can represent 256 symbols.
Obviously, ASCII cannot represent all the languages and characters in the world, so a new character encoding is needed, namely Unicode.
Unicode (Uniform Code, Universal Code, Single Code) is an encoding used on computers. Unicode was created to solve the limitations of traditional character encoding. It sets a uniform and unique binary encoding (and ultimately, binary encoding) for each character in each language. It is stipulated that all characters and symbols are represented by at least 16 bits (1 bit is 2 bytes), which is 216=65536.
UTF-8 is the compression and optimization of Unicode code. Instead of using at least two bytes, it classifies all characters and symbols: the byte in the ascii code is represented by one byte, and the European symbols are represented by two. Byte representation, East Asian characters are represented by three bytes. . . .
So when the python interpreter loads the .py file, it encodes the content, and the default is ascii encoding. If the code is as follows and Chinese characters appear, the encoding will fail.
Failure: The ascii code cannot represent Chinese.
Correction: It should be displayed to tell the python interpreter what encoding to use to execute the source code, namely:
#! /usr/bin/env python # -- coding: utf-8 -- print "Hello, world"
1 #! /usr/bin/env python
23 print "Hello world"
- Execute script and pass in parameters
Python has a large number of modules, which makes the development of Python programs very concise. The class library includes three:
- Modules provided inside Python
- Open source modules in the industry
- Modules developed by programmers
Python provides a sys module, where sys.argv is used to capture the parameters passed in when executing the python script
/usr/bin/env python # -- coding:utf-8 -- import sys args = sys.argv print(args)
Results of the:
[' D:/PycharmProjects/test/test08.py','Zhang San','Li Si','Wang Wu']
- Usage of getpass in python The function of getpass in python is to enter the password invisible to open the terminal of pycharm