durusmail: quixote-users: Re: Htmltext and latin-1 characters
Htmltext and latin-1 characters
2006-05-10
Re: [Cheetahtemplate-discuss] Htmltext and latin-1 characters
2006-05-10
Re: [Cheetahtemplate-discuss] Htmltext and latin-1 characters
2006-05-11
Re: [Cheetahtemplate-discuss] Htmltext and latin-1 characters
2006-05-10
2006-05-11
2006-05-11
2006-05-11
2006-05-11
2006-05-11
2006-05-13
2006-05-13
2006-05-15
Re: Htmltext and latin-1 characters
2006-06-04
2006-06-06
2006-06-07
2006-06-08
Re: Htmltext and latin-1 characters
2006-06-05
2006-06-05
2006-06-05
Re: Htmltext and latin-1 characters
Akihiro KAYAMA
2006-06-05
In article ,
Neil Schemenauer  writes:

nas> >>>> print htmltext(U"A\xa0B")
nas> > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in
nas> > position 1: ordinal not in range(128)
nas>
nas> Does this work for you:
nas>
nas>     >>> print U"A\xa0B"
nas>
nas> It works for me because:
nas>
nas>     >>> import sys
nas>     >>> sys.stdout.encoding
nas>     'UTF-8'
nas>
nas> Sometimes stdout is 'ascii' and so you have to manually set the
nas> encoding, eg:
nas>
nas>     >>> import sys, codecs
nas>     >>> sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

FYI: On UNIX, the environment variables LANG/LC_CTYPE/LC_ALL also
affect Py_FileSystemDefaultEncoding. (I didn't know Python had such
mechanism. Why they don't affect setdefaultencoding?)

% python
>>> import sys, os
>>> sys.stdout.encoding
'EUC-JP'
>>> os.environ['LANG']
'ja_JP.eucJP'
>>> print U"A\xa0B"
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeError: EUC-JP encoding error: invalid character \xa0

% env LANG=ja_JP.utf8 python
>>> import sys
>>> sys.stdout.encoding
'UTF-8'

-- kayama
reply