string.encode on HP-UX

Christopher T King squirrel at WPI.EDU
Thu Jul 22 16:25:12 CEST 2004


On Thu, 22 Jul 2004, Richard Townsend wrote:

> Further, if I put the following in sitecustomize.py:
> 
> import encodings
> print dir(encodings)
> 
> I get:
> 
> ['CodecRegistryError', '__builtins__', '__doc__', '__file__', 
> '__name__', '__path__', '_cache', '_import_tail', 
> '_norm_encoding_map', '_unknown', 'codecs', 'exceptions', 
> 'normalize_encoding', 'search_function', 'types']
> 
> Notice there is no 'aliases' attribute.

Oops, I had only tested it at the prompt :P I had assumed sitecustomize.py 
was run after everything was set up.

This code uses a more defined interface for altering the codecs registry, 
uses 'ascii' instead of 'latin_1' (to prevent some confusion), and 
I've actually tested it in sitecustomize.py:

import codecs

def roman8(n):
    if n=='roman8':
        return codecs.lookup('ascii')

codecs.register(roman8)

This achieves the same effect as the aliases trick (which I'm surprised 
didn't work for you at the prompt), but is less tricksy and should 
therefore work better.




More information about the Python-list mailing list