• Login or register

discuss.effbot.org

  • Popular
  • Recent
  • 1 point by Lighioaie 10 months ago on Python Unicode Objects 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!

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