我正在运行 Python 2.6.6。
猫 tbuild.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from mako.template import Template
_template="""
% for v in my_list:
${'abc'.encode('utf-8')}
${'風連町?'.encode('utf-8')}
% endfor
"""
print Template(_template).render_unicode(my_list = [1, 2],
input_encoding='utf-8',
output_encoding='utf-8',
encoding_errors='replace'
)
./tbuild.py gives.
File "./tbuild.py",
line 15, in <module> print Template(_template).render_unicode(my_list = [1, 2],
File "/usr/lib/python2.6/site-packages/mako/template.py",
line 91, in __init__ (code, module) = _compile_text(self, text, filename)
File "/usr/lib/python2.6/site-packages/mako/template.py",
line 357, in _compile_text node = lexer.parse()
File "/usr/lib/python2.6/site-packages/mako/lexer.py",
line 192, in parse self.filename,)
File "/usr/lib/python2.6/site-packages/mako/lexer.py",
line 184, in decode_raw_stream 0, 0, filename)
mako.exceptions.CompileException: Unicode decode operation of
encoding 'ascii' failed at line: 0 char: 0
如果我删除带有日语的行,它可以正常工作。显然,我想念一些基本的东西。
谢谢你的帮助,eo