, after restarting the interpreter, it will be found that the encoding is reset to the default ASCII, Then there is no way to modify the program or the system's default code at once.There are 2 ways to set the default encoding for Python:A solution is to add the following code to the program:python code NBSP;NBSP;
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' UTF8 ')
Another option is to create a new sitecustomize.py under the
, a tool that gives you a deep understanding of your own business areas-the real things you need, the way you want to conquer problems, and deal with problems. If you haven't done so yet, please try it. The following articles will give you some hints:
http://www.oreillynet.com/lpt/a/5463
http://www.oreillynet.com/lpt/a/5584
Http://wiki.cacr.caltech.edu/danse/index.php/Unit_testing_and_Integration_testing
Http://docs.python.org/library/unittest.html
(SYS)Sys.setdefaultencoding (' Utf-8 ')This setdefaultencoding is set when the system starts, that is, when you enter Python >>> in the console, the system automatically reads a file, so you must re-reload when you are using Python.The input will then be successful.2 Output UTF8 encodingOutput UTF8 encoding This problem I have not solved, the current approach is to import into the TXT file ...3 Output List garbledIf the list is garbled, the contents
\xad\xe6\x96\x87 '. Decode (' utf-8 ')ChineseWhen manipulating strings, we often encounter mutual conversions between Str and bytes. To avoid garbled problems, you should always use UTF-8 encoding to convert str and bytes.Because the Python source code is also a text file, so when your source code contains Chinese, it is important to specify that you save it as UTF-8 encoding when you save it. When the Python
Personally, I like Python very much, and of course I have a lot of reasons to recommend you to learn Python. I only say two. One is simple, the other is to write Python pay high. I think these two reasons are enough, right. Buy a book, put on a pycharm, Knock over the example of the
http://www.douban.com/note/134971609/PEP8 Python Coding SpecificationA code orchestration1 indent. Indentation of 4 spaces (the editor can do this), no tap, no mix of taps and spaces.2 The maximum length per line is 79, the line break can use backslashes, preferably with parentheses. The newline point is to hit enter after the operator.There are two empty lines between the 3 class and the top-level function
PEP8 Python Coding SpecificationA code orchestration1 indent. Indentation of 4 spaces (the editor can do this), no tap, no mix of taps and spaces.2 The maximum length per line is 79, the line break can use backslashes, preferably with parentheses. The newline point is to hit enter after the operator.There are two empty lines between the 3 class and the top-level function definition, an empty line between th
The PEP8 Python Coding specification is for informational purposes only and does not have to be fully adhered to.A code orchestration1 indent. Indentation of 4 spaces (the editor can do this), no tab, and no combination of tabs and spaces.2 The maximum length per line is 79, the line break can use backslashes, preferably with parentheses. The newline point is to hit enter after the operator.There are two em
which such objects are ordered is random but will always be consistent. when any one operand is a complex number, the, =, > , and > = operators throw TypeError exception. Non-identical instances of a class are typically not equal unless the class defines the __eq__ () or __cmp__ () method.An instance of a class cannot typically be sorted with other instances of the same class or other types of objects unless the class defines a sufficiently rich comparison method (__ge__ (),__le__ (),__gt__
is, first use the system default code for encode3. Determine if the byte string is utf-8 encoded, and if so, the outputTo solve the problem of sublime text under Windows, there are two ways to do this:1. Add the following code to the program's headImport'utf-8'if sys.getdefaultencoding ()! = Default_ Encoding: Reload (SYS) sys.setdefaultencoding (default_encoding)There is said to be inserted into the sublime_plugin.py, but the test, no2, add pythonioencoding in the system environment vari
ObjectiveThis article is to read the "Python Coding Rule" summarizes the most elite and simple coding specifications, according to each person's preferences, some places will have different choices, I just do the most simple and easy choice for their own, for your reference only.Important Principles
It's important to maintain style consistency, but most
Python attempts to convert between a byte string and a string in a way that is not perceived. In different transformations, Python attempts to convert directly into byte strings and Unicode strings, where conditions permit.For example, when you concatenate a byte string and a Unicode byte together. According to the previous introduction , it makes no sense to convert between different types without using en
The problem of Chinese coding has always been a headache in Python program design, and this paper summarizes it in detail. Specific as follows:
When the string is: ' \U4E2D\U56FD '
>>>s=[' \u4e2d\u56fd ', ' \u6e05\u534e\u5927\u5b66 ']>>>str=s[0].decode (' Unicode_escape ') #.encode ("EUC_KR") >>>print str China
When the string is: ' East Asian Studies Group One '
>>>print UNICHR (19996) east
Ord () su
Python is so popular because it works in many different areas, and the most widely used areas of Python today include Python Web (back-end) development, data analysis Mining, web crawlers, machine learning AI, devops development, and more. Whichever direction you choose, the basics of Python will help you get better at
Encoding of Python code filesThe py file is ASCII encoded by default, and Chinese will make an ASCII-to-system-default-encoding conversion when displayed, and an error will occur: Syntaxerror:non-ascii character. You need to add an encoding indication on the first or second line of the code file:
# coding=utf-8 ##以utf-8编码储存中文字符
print ' Chinese ' as above directly input string is processed accor
Python2 the default encoding format is ASCII format, the Chinese characters cannot be printed correctly when the encoding format is not modified, so the error occurs when reading Chinese.The workaround is to add #-*-Coding:utf-8-*- at the beginning of the fileI add this to: #coding = UTF-8 or #coding: UTF-8 After modification:python3.x source files use utf-8 encoding by default, so you can parse Chinese nor
Python coding is a profound knowledge, and I am still bleeding python, so I am currently required to be only in their own crawl Web page to obtain Chinese information without error, only that, for other deeper content with the accumulation of knowledge presumably have a deeper understanding. The following is not my original understanding, but on the internet to r
0. PrefaceThis article is to read the "Python Coding Rule" summarizes the most elite and simple coding specifications, according to each person's preferences, some places will have different choices, I just do the most simple and easy choice for their own, for your reference only.1. Important PrinciplesA. It is important to maintain style consistency, but most im
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.