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!
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!