Why there is no "setdefaultencoding" in sys module?

Thomas Jollans thomas at jollans.com
Fri Jul 9 12:35:34 EDT 2010


On 07/09/2010 06:06 PM, crow wrote:
> On Jul 10, 12:04 am, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote:
>>> So, my questions: why there is no setdefaultencoding in sys module? if I
>>> want to change system's default encoding, what should I do?
>>
>> I think the answer is:
>>
>> Don't.
>>
>> If you do, you will break built-ins.
>>
>> http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e...
>>
>> Googling will find many discussions about this.
>>
>> --
>> Steven
> 
> Interesting, so it has been removed from python? then why it's still
> in document... It's really misleading.

Actually, it's still there. Lurking in the corners of sys. But site.py
knows it's evil:

% python
Python 2.6.5+ (release26-maint, Jul  6 2010, 12:58:20)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.setdefaultencoding
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setdefaultencoding'
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding
<built-in function setdefaultencoding>
>>>





More information about the Python-list mailing list