string.encode on HP-UX

Christopher T King squirrel at WPI.EDU
Wed Jul 21 10:00:04 EDT 2004


On Wed, 21 Jul 2004, Richard Townsend wrote:

> Using Python-2.3.4 on HP-UX11i, the following code:
> 
>   import locale
>   loc = locale.setlocale(locale.LC_ALL)
>   print 'locale =', loc
>   loc = locale.nl_langinfo(locale.CODESET)
>   print 'locale =', loc
>   print 'hello'.encode(loc, 'replace')
> 
> produces:
> 
>   locale = C C C C C C
>   locale = roman8
>   Traceback (most recent call last):
>     File "test_locale.py", line 13, in ?
>       print 'hello'.encode(loc, 'replace')
>   LookupError: unknown encoding: roman8
> 
> [The same code on SUSE 9.1 doesn't raise an exception].

My guess is roman8 is HP-UX's version of latin_1.  Setting an alias fixes 
this:

>>> import encodings
>>> encodings.aliases.aliases['roman8']='latin_1'
>>> 'hello'.encode('roman8')
'hello'

You can add those first two lines to a sitecustomize.py file, located 
somewhere in your Python path (generally ~/site-packages/ or 
/usr/local/lib/python2.X/ should work).




More information about the Python-list mailing list