• Login or register

discuss.effbot.org

  • Popular
  • Recent
  • Python Unicode Objects (effbot.org)

    Some observations on working with non-ASCII character sets

    1 point by effbot 1 year ago
    • 1 comment
  • 1 point by Lighioaie 10 months ago 0 children

    Thanks for the article!

    One more thing to add: there is one parameter to the encode() method which makes it priceless for me, especially when working with HTML.


    >>> my_unicode_str = u'Chuchumbé - ¡Caramba Niño!'
    >>> my_unicode_str.encode('us-ascii', 'xmlcharrefreplace')
    'Chuchumbé - ¡Caramba Niño!'

    The result is well suited to be printed on a dumb ASCII console or on a web page.

    I would agree that having to use this sort of hack is most likely an indicator of bad coding practice, and using this in a web app where most characters are non-ascii would probably be totally insane. But nobody is perfect!

    • link
    • reply
  • Widget
  • Recent Comments
  • Leaders
Powered by