Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # encoding: utf-8
- #
- # Copyright (c) 2010 Doug Hellmann. All rights reserved.
- #
- """Error handling with character map encodings.
- """
- #end_pymotw_header
- import codecs
- from codecs_invertcaps_charmap import encoding_map
- text = u'pi: π'
- for error in [ 'ignore', 'replace', 'strict' ]:
- try:
- encoded = codecs.charmap_encode(text, error, encoding_map)
- except UnicodeEncodeError, err:
- encoded = str(err)
- print '{:7}: {}'.format(error, encoded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement