import codecs codecs.register_error('spacer',lambda ex: (u' ',ex.start + 1)) s = 'spam\xb0\xc0eggs\xd0bacon'.decode('utf8','spacer') print s.encode('utf8')
打印:
spam eggs bacon