"Allen Fowler" <allen.fow...@yahoo.com> wrote in message news:59796.73163...@web45608.mail.sp1.yahoo.com...
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