Getting Spyce to print Unicode
Andy Sy <[email protected]> Wed, 17 Oct 2012 11:39:53 +0800
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
This one fails:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body><% print u"CJ7 \u2665" %></body>
</html>
with:
UnicodeEncodeError: 'ascii' codec can't encode character
This tip from http://www.gossamer-threads.com/lists/python/python/701452 will fix it:
<%\
import sys,codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
print u"CJ7 \u2665"
%>
However, Python expressions still fail with a UnicodeEncodeError:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<%\
import sys,codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
s = u"CJ7 \u2665"
# below works
print s
%>
<!-- this one generates error --><%= s %>
</body>
</html>
Any tips on how to get this to work?
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct