UnicodeError...

Teemu Luojola tempe at pp.inet.fi
Tue Jul 30 11:58:34 EDT 2002


Martin v. Loewis wrote:

> Teemu Luojola <tempe at pp.inet.fi> writes:
> 
> 
>>This
>>problem is dealt in Python FAQ in chapter 4.102. and the following
>>solution is given:
>>
>>
>>> # Set the string encoding used by the Unicode implementation.
>>>    # The default is 'ascii'
>>>    encoding = "ascii" # <= CHANGE THIS if you wish
>>>
> [...]
> 
>>The problem is, that sys doesn't include setdefaultencoding(). 
>>
> 
> I don't believe you. Did you try to modify this very location in
> site.py? At that point, sys.setdefaultencoding is still present.
> 
> 


Well, here is the result, when I entered precisely what was told in FAQ:

>>>> encoding = "ascii"
>>>> import locale
>>>> loc = locale.getdefaultlocale()
>>>> if loc[1]:
> 	encoding = loc[1]
> 
> 	
>>>> if encoding != "ascii":
> 	import sys
> 	sys.setdefaultencoding(encoding)
> 
> 	
> Traceback (most recent call last):
>   File "<pyshell#9>", line 3, in ?
>     sys.setdefaultencoding(encoding)
> AttributeError: 'module' object has no attribute 'setdefaultencoding'


And here are some dir listings:

>>>> import site
>>>> site
> <module 'site' from 'F:\PYTHON22\lib\site.pyc'>
>>>> dir(site)
> ['_Helper', '_Printer', '__builtin__', '__builtins__', '__doc__', '__file__', '__name__', '_dirs_in_sys_path', '_init_pathinfo', '_test', 'addpackage', 'addsitedir', 'dircase', 'encoding', 'here', 'makepath', 'os', 'prefix', 'prefixes', 'sitedir', 'sitedirs', 'sys']
>>>> dir(site.sys)
> ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__stdin__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getrecursionlimit', 'getrefcount', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'maxint', 'maxunicode', 'modules', 'path', 'platform', 'prefix', 'ps1', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version', 'version_info', 'warnoptions', 'winver']
>>>> dir(sys)
> ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__stdin__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getrecursionlimit', 'getrefcount', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'maxint', 'maxunicode', 'modules', 'path', 'platform', 'prefix', 'ps1', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version', 'version_info', 'warnoptions', 'winver']


How it is possible, that sys.setdefaultencoding() does not exist?
Where to get a proper module?


- Teemu




More information about the Python-list mailing list