Python encoding Problem: unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 0-1: Ordinal not in range (12

Source: Internet
Author: User

Today, I installed the Pyscripter editor, and just to write the code, suddenly an exception occurred:

<span style= "Font-size:14px;color: #ff0000;" >>>> Traceback (most recent):
File "<string>", line 378, in Findmoduleorpackage
File "<string>", line 367, in Find_dotted_module
Unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 0-1: Ordinal No in range </span>

When Python is installed, the default encoding is ASCII. It is often the case that it cannot handle non-ASCII encoding. You will need to manually modify its coded character set at this time.

Query system default encoding:

In the shell, enter Python and enter the Python interpreter.
>>>import SYS
>>>sys.getdefaultencoding ()

Can.


If you want to set the default encoding:

>>>sys.setdefaultencoding (' UTF8 ')

You can set the default encoding to UTF8.

However, if you restart the Python interpreter, the default encoding becomes ASCII again.

If you want to permanently set the system default encoding to UTF8, then:

Create a new sitecustomize.py in the Python lib\site-packages folder, with the following content:

# Encoding=utf8
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' UTF8 ')

Reference

http://blog.csdn.net/liuxingyu_21/article/details/27487391

Http://www.cnblogs.com/sislcb/archive/2008/11/26/1341453.html

Http://www.pythonfan.org/blog-3526-1416.html

Python encoding Problem: unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 0-1: Ordinal not in range (12

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.