Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ About Python default character set     - Is Linux the most secure operating system (Linux)

- Linux iptables port mapping settings (Server)

- Rails project prepared some tips small experience (Linux)

- Linux permissions Detailed (Linux)

- Nginx logging client ip (Server)

- Samba public folder permissions (Server)

- Linux log management tools Logrotate (Linux)

- Installation Eduspec university management systems 17 Linux Mint (Server)

- MySQL database under Linux to achieve automatic backup scheduled backup day (Database)

- Several Methods of SSH Auto - login (Linux)

- Replace element and non-replaced elements of learning (Programming)

- Simple RPM package production (Linux)

- impdp error ORA-31631, ORA-39122 (Database)

- Java memory area and memory overflow exception (Programming)

- Use matplotlib scientific drawing in Linux (Linux)

- Hardware Firewall Basics (Linux)

- Use Elasticsearch + Logstash + Kibana set up centralized log Practice Analysis Platform (Server)

- Database start listening TNS-12537, TNS-12560 error (Database)

- imp / exp Oracle Database import and export commands (Database)

- C ++ complex class of operator overloading (Programming)

  About Python default character set
  Add Date : 2018-11-21      
  This article briefly describes the history and character sets to configure Python program used in the analysis.

Background: In writing the script when the inevitable will design some variables related to the content and Chinese. This time for a Python novice (including me) is how to configure the python so that it can correctly identify the Chinese content within the program will become very troublesome. This article will briefly describes how to configure Python character sets and some related historical information.


Python's default character set

Python's default character set has been changed in several major versions, the following are the various versions of the default character set include:

Python2.1 and before: latin1
After Python2.3 and, Python2.5 ago: latin1 (but have non-ASCII character set character put forward WARNING)
Python2.5 and beyond: ASCII
In addition, in the PEP also proposed in the follow-up version of the default character set is UTF-8 adjustment


How to configure the default character set (Python2.5 ago)

Python script file to resolve the current configuration using the default character set at 2.5 before it is very difficult. Because these older versions do not support similar shebang of coding configuration. Although the old version before 2.5 is outdated, it was still mention of these versions of the character set configuration method. The configuration works by sys.setdefaultencoding () function. But the tangled, this function site.py (a script to run automatically at startup Python) is deleted. So the Internet there have been several versions:

reload (sys)
Modify sitecustomize.py configure global default character set
Both methods can just work, not elegant. More specifically, the mode of operation can be found in the discussion on stackoverflow


How to configure the default character set (Python2.5 and beyond)

Python2.5 after the default character set configuration on a lot simpler. Just behind Shebang (ie #! / Usr / bin / python line after), a line of character set configuration on the line to keep up. Writing regular character set configuration lines need to comply with such a regular coding [: =] \ s * ([- \ w.] +). That can take effect the following wording:

#! / Usr / bin / python
# Coding = utf8

#! / Usr / bin / python
# - * - Coding: utf8 - * -
Or more

#! / Usr / bin / python
# Vim: set fileencoding = < encoding name>:
These can work in.
- Installation Eduspec university management systems 17 Linux Mint (Server)
- Text editing and viewing text Linux command (Linux)
- Ubuntu 14.10 Install Ubuntu Touch Music App 2.0 (Linux)
- Experts teach you safety precautions Linux Sniffer (Linux)
- Java MD5 encryption implementation (Programming)
- Enterprise Hadoop cluster architecture - DNS installation (Server)
- Ubuntu uses under KVM + Qemu virtual machine build (Linux)
- RedHat virtual machine to install VMware Tools (Linux)
- Use HttpClient remote interface testing (Programming)
- Linux and Windows Security Topics (Linux)
- Smack 4.1.x Upgrade Guide (Linux)
- ctop: monitor container performance Linux command line artifact (Linux)
- Arrow keys, backspace key garbled in Python-2.7.5 Interactive Mode under CentOS 5.8 (Linux)
- zBackup: A versatile tool to remove duplicate backup (Linux)
- Supervisor Installation and Configuration (Server)
- iTerm - let your command line can also be colorful (Linux)
- stat - Get more information than ls (Linux)
- Configuring Android NDK development environment for Mac OS X (Linux)
- To achieve Linux Security (Linux)
- CentOS 6.4 dial-up Raiders (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.