If you get an error with a string like "ABC", maybe the non-ASCII character is somewhere else. In the template source perhaps?
In any case, use Unicode strings throughout your application to avoid this kind of problems. If your data source provides you with byte strings, you get unicode strings with byte_string.decode('utf-8')
, if the string is encoded in UTF-8. If your source is a file, use the StreamReader
class in the codecs module.
If you're unsure about the difference between Unicode strings and regular strings, read this: http://www.joelonsoftware.com/articles/Unicode.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…