Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2010 Doug Hellmann. All rights reserved.
  5. #
  6. """Error handling with character map encodings.
  7. """
  8. #end_pymotw_header
  9.  
  10. import codecs
  11. from codecs_invertcaps_charmap import encoding_map
  12.  
  13. text = u'pi: π'
  14.  
  15. for error in [ 'ignore', 'replace', 'strict' ]:
  16. try:
  17. encoded = codecs.charmap_encode(text, error, encoding_map)
  18. except UnicodeEncodeError, err:
  19. encoded = str(err)
  20. print '{:7}: {}'.format(error, encoded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement