[Tutor] What is the trick ???!

Karim karim.liateni at free.fr
Thu May 12 21:24:37 CEST 2011


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'
 >>>

:-\ ???


More information about the Tutor mailing list