Class has method that shows in intellisense, but gives an error when running it
I'm tring to set the default encoding of my console to UTF-8 so it can display cyrillic letters and accented letters.
Here is my code:
from Parser import parser
import sys
print sys.getdefaultencoding()
sys.setdefaultencoding('utf-8')
Output:
ascii
Traceback (most recent call last):
File "C:\Users\Sergio.Tapia\Documents\NetBeansProjects\BabylonPython\src\TestingGrounds.py", line 5, in <module>
sys.setdefaultencoding('utf-8')
AttributeError: 'module' object has no attribute 'setdefaultencoding'
The weird thing is, when pressing the '.' after 开发者_运维技巧sys to see what method it has, setdefaultencoding is shown as a possible choice. Any suggestion on what to do?
The function sys.setdefaultencoding()
does exist but is removed from sys
' dictionary by site.py
itself.
On my machine, site.py
contains the following comment:
# Remove sys.setdefaultencoding() so that users cannot change the
# encoding after initialization. The test for presence is needed when
# this module is run as a script, because this code is executed twice.
From http://docs.python.org/library/sys.html
This function is only intended to be used by the site module implementation and, where needed, by sitecustomize.
精彩评论