"Allen Fowler" <[email protected]> wrote in message news:[email protected]...
Hello,

I've been using "data.encode('ascii','replace')" to force an ASCII string out of Unicode data, with "?" in the place of non-ASCII letters.

However, now I want to use a blank space (or maybe a dash) instead of a question mark.

How do I do this?

See codecs.register_error().  Here's a simplistic example:

# coding: utf-8
import codecs

def handler(e):
   return (u'-',e.start + 1)

codecs.register_error('mine',handler)
s = u'My name is 马克.'
print s.encode('ascii','mine')

OUTPUT:
My name is --.


-Mark

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to