1. Code Conversion
General hard disk storage is utf-8, read into in-memory Unicode, and how they are converted
A = ' hello ' \xe4\xbd\xa0\xe5\xa5\xbd ' <type ' str ' >
b = u ' Hello ' u ' \u4f60\u597d ' <type ' Unicode ' >
A.decode (' utf-8 ') u ' \u4f60\u597d ' (utf-8 format decoded to Unicode)
B.encode (' utf-8 ') ' \XE4\XBD\XA0\XE5\XA5\XBD ' (Unicode format encrypted to Utf-8)
Note: In the python2.7 version you need to convert as above, in the script to display Chinese,
Just add # _*_ coding:utf-8 _*_ or #coding =utf-8 at the beginning of the file.
After the python3.4 version, no conversion is required
2. Call the system command and deposit the variable:
1.import OS
A = Os.system (' df-th ')
b = Os.popen (' df-th ', ' R ') returns a file object
2.import commands
c = commands.getoutput (' df-th ') returns a string
3. SYS call
Import Sys
Sys.exit
Print Sys.arg
Sys.path
4. Import Template Method:
1.import sys [as newname]
2.from sys import argv or (*)
It is recommended that the first, the second imported object or variable will conflict with the current variable.
5. User interaction:
In the python2.7 version
Raw_input: interactive input string;
Input: Enter numbers interactively;
In the python3.4 version only raw_input, want to get the number, need to make an int transformation.
Example:
#_ *_ Coding:utf-8 _*_
info = ' This var is printed out ... '
Name = raw_input (' Please input your name: ')
age = Int (raw_input (' Age: '))
#age = input (' Age: ')
Job = Raw_input (' Job: ')
Salary = input (' Salary: ')
Print type (age)
Print ""
Personal Information of%s:
Name:%s
Age:%d
Job:%s
Salary:%d
--------------------------
"% (Name,name, age,job,salary)
This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1651859
Python Learning Notes