[Tutor] What is the trick ???!

Karim karim.liateni at free.fr
Thu May 12 21:38:52 CEST 2011


On 05/12/11 21:24, Karim wrote:
>
> Hello
>
> See below, I was surprised about finding hidden function in module sys:
>
> karim at Requiem4Dream: python2.7
> Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> sys.getdefaultencoding()
> 'ascii'
> >>> sys.setdefaultencoding()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'setdefaultencoding'
> >>>
> karim at Requiem4Dream:~/build/OpenProcessManager/test$ python2.7
> Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> sys.getdefaultencoding()
> 'ascii'
> >>> sys.setdefaultencoding('utf-8')
> 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('utf-8')
> >>> sys.getdefaultencoding()
> 'utf-8'
> >>>
>
> :-\ ???
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Ok I found the trick at 
http://docs.python.org/library/sys.html#sys.setdefaultencoding.
The function is removed dynamically at startup when reload I get the 
nominal one
(the original).

Sorry for the disturb.
Cheers
Karim


More information about the Tutor mailing list