specified variable value)
. [0-9] (Specify the number of decimal digits or the maximum string length)
Note: If you use more than one of the above format values, they must be used in the order above and cannot be disrupted.
Arg1
Necessary. Specifies the parameter that is inserted into the first% symbol in the format string.
Arg2
Necessary. Specifies the parameter that is inserted into the second% symbol in the format string.
arg++
Option
):File "chinesetest. py", line 3, inPrintOpen ("test.txt"). Read (). Decode ("UTF-8 ")Unicodeencodeerror: 'gbk' codec can't encode character U'/ufeff 'inPosition 0: Illegal multibyte Sequence
Originally, some software, such as Notepad, will insert three invisible characters at the beginning of the file when saving a file encoded in UTF-8 (0xef 0xbb0xbf (BOM ).Therefore, we need to remove these characters during reading. The codecs module in Python defines this constant:# Coding = GBKImport code
. Decode ("UTF-8 ")Result: ABC (Chinese)
(4) A few issues left behindIn the second part, we use the Unicode function and decode method to convert STR to Unicode. Why do the parameters of these two functions use "GBK?The first response is that GBK (# Coding = GBK) is used in our encoding statement, but is it true?Modify the source file:# Coding = UTF-8S = "Chinese"Print Unicode (S, "UTF-8 ")Run, error:Traceback (most recent call last ):File "chinesetes
the UTF-8 encoded binaryFive, Python2 and Python3 coding difference1. There are two types of string in Python2 str and UnicodeSTR typeWhen the Python interpreter executes the code that produces the string (for example, s= ' forest '), it requests a new memory address and then encodes the ' forest ' into the encoding format specified at the beginning of the file, which is already the result of encode, so s can only be decode. Again encode will be an error.#_ *_coding:gbk_*_2 #!/usr/bin/env pytho
and filename are specified simultaneously3. Output logs to both file and screen at the same time
Import loggingLogging.basicconfig (level=logging. DEBUG,format= '% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s ',Datefmt= '%a,%d%b%Y%h:%m:%s ',Filename= ' Myapp.log ',Filemode= ' W ')##################################################################################################定义一个StreamHandler, print Info-level or higher log information to a standard err
redirection for Output Route-n|awk ' Nr!=1{print} ' >./fsformatted outputNetstat-anp|awk ' {printf '%-8s%-8s%-10s\n ", $1,$2,$3} ' printf represents a format output% formatted output delimiter-8 length of 8 characters s means the string type prints the first three fields per line, Specifies the first field output string type (length 8), the second field output string type (length 8), the third field output
default values for each parameter fromColorlogImportColoredformatterformatter=Coloredformatter ("% (Log_color) s% (levelname) -8s% (reset) s% (blue) s% (message) s", Datefmt=None, Reset=True, Log_colors={ 'DEBUG':'Cyan', 'INFO':'Green', 'WARNING':'Yellow', 'ERROR':'Red', 'CRITICAL':'Red,bg_white',}, Secondary_log_colors={}, Style='%')2. Use of Secondary_log_colorsThe secondary log color is a method of selecting mult
and filename are specified simultaneously3. Output logs to both file and screen at the same time
Import loggingLogging.basicconfig (level=logging. DEBUG,format= '% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s ',Datefmt= '%a,%d%b%Y%h:%m:%s ',Filename= ' Myapp.log ',Filemode= ' W ')##################################################################################################定义一个StreamHandler, print Info-level or higher log information to a standard err
This article summarizes some simple basic output format form, the following words do not say more, to see the detailed introduction bar.
A, print string
>>> print "I ' m%s"% ("Jihite")
I ' m jihite
Second, print integer
>>> print "I ' m%d years old" (%)
i ' M years old
Third, printing floating point numbers
>>> print "π=%f"% (3.1415926)
π=3.141593
Printing floating-point numbers (specify how many decimal places to keep)
>>> print "π=%.3f"% (3.14159
Read Catalogue
1. Print a string
2. Printing integers
3. Print floating-point numbers
4. Print floating-point numbers (Specify the number of decimal places reserved)
5. Specify the placeholder width
6. Specify the placeholder width (left-justified)
7. Specify placeholders (only 0 placeholders)
8. Scientific counting method
1. Print a string>>> print "I ' m%s"% ("jihite") I ' m jihite2. Printing integers>>> print "I ' m%d years old"% (+) I ' M years old3.
()Level: Sets the log levels by default to logging. WARNINGStream: Specifies the output stream that will log, can specify output to Sys.stderr,sys.stdout or file, default output to Sys.stderr, stream is ignored when stream and filename are specified simultaneously3. Output logs to both file and screen at the same time
Import loggingLogging.basicconfig (level=logging. DEBUG,format= '% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s ',Datefmt= '%a,%d%b%Y%h:%m
This article comes from NetEase cloud community.
Time Wheel ImplementationA time wheel is a circular data structure, divided into multiple lattices.Each lattice represents a period of time, the shorter the time, the higher the accuracy.Each grid is saved with a list of expired tasks in that grid.The pointer rotates over time and executes the expiration task in the corresponding grid.Noun Explanation:
Time Lattice: a block in a circular structure for storing delayed tasks
Pointer: A time
① output Route-n|awk ' Nr!=1{print > './fs '} ' ② use redirection for Output Route-n|awk ' Nr!=1{print} ' >./fsformatted outputNetstat-anp|awk ' {printf '%-8s%-8s%-10s\n ", $1,$2,$3} ' printf represents a format output% formatted output delimiter-8 length of 8 characters s means the string type prints the first three fields per line, Specifies the first field output string type (length 8), the second field
Ubuntu7.10 hard disk installation with image text (alternate version, text installation Interface) 1. Download The Ubuntu7.10 CD image first download the CD image required for hard disk installation. I like to use ubuntu-7.10-alternate-i386.iso for hard disk installation. : X86: http://releases.ubuntu.com/releases/7.10/ubuntu-7.10-alternate-i386
Ubuntu7.10 hard
the DLL search path.
Alternate search order for desktop applications
The standard search order used by the system can be changed by callingLoadLibraryExFunctionLoad_with_altered_search_path. The standard search order can also be changed by callingSetdlldirectoryFunction.
Windows XP:Changing the standard search order by calling
SetdlldirectoryIs not supported until Windows XP with Service Pack 1 (SP1 ).
If you specify an
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.