Recently busy a large GIS software system, so spare no time to study the open source technology, throughout the current open-source desktop GIS software field, the most bull fork is the famous Quantum GIS, referred to as QGIS. People who have done GIS know that ESRI ArcGIS is by far the world's most bull in the field of GIS software, but because it is commercial software, its price is prohibitive for the general public. Therefore, the search for an open source free and functional and can be Belittlin ' with the GIS software is inevitable. I after a lot of comparison, QGIS deserved!
But for me, because I am a GIS software application development, and only proficient in Java and. NET technology, and QGIS only support C + + and Python two development languages, for most people, the C + + technology threshold is really a bit difficult to engage in. I am no exception, because Python popularity is getting higher and better, so I chose Python
It's important to say that the people who have played Python know that Python development is typically written in Python's own, IDLE integrated development environment. When I choose a book, install the Python software and configure all the relevant environments, I start the Python programming journey ...
At first, everything is OK, follow the book Step by Step, a "Hello python!" The string is elegantly printed out ...
Wait, I am Chinese, print point Chinese out try Bai, so I came to a print ' I am Chinese ', the problem came out, the console printed a string of similar ' \xd6\xd0\xce\xc4′- like ghost. I suddenly wonder, this thing can not play Chinese? So ran to ask Google, Niang and other aunt, still did not find the ultimate solution. So I think of a word, "Ask for yourself", according to years of Java and. NET experience to tell themselves, the problem must be out of the Encoding, finally Kung Fu, found a solution.
Problem Analysis:
First of all, the default encoding in my Windows 7 is GBK encoding;
Secondly, inside Python, the default character encoding should be the same as the operating system, and most of our Chinese use the Windows Chinese system, that is, the default is GBK encoding. In the IDLE, the direct input Chinese characters, in fact, is GBK encoding;
Analysis here, theoretically, should be no problem, why still out of the ghost? We know that when dealing with Chinese in other languages such as Java, no exception is associated with Encoding. Therefore, Python is no exception, since the environment is no problem, the problem must be that the source code file encoding and the code of the IDLE editor is inconsistent in the setup, resulting in problems. Follow your own ideas, first I put my own Python source file into a Unicode encoding format, and then at the beginning of the source code to add the following sentence:
#-*-CODING:GBK-*-
...... Other Python source code ...
Then, choose the Idle menu options--Configure idle ... Open the IDLE configuration option, switch to the General tab, locate the default Source Encoding setting, select the Locale-defined option, click the Apply button, and then click OK to save the settings.
Close exit idle and rewrite to open the idle integrated development environment, at which point you try again:
>>> Print ' I am a Chinese '
I am a Chinese
Haha, congratulations, you have succeeded! Beautiful and elegant "I am Chinese" to print out ...
Python IDLE Chinese garbled problem