Open yuzhou346694246 opened 7 years ago
同问
这个应该是编码问题,因为windows下默认编码是gbk,所以会报错。 如果是3.5的话,在#94行加上encoding='utf8'
with open(os.path.join(os.path.dirname(__file__), 'plot.j2'), encoding='utf8') as f:
但是还会报
TypeError: a bytes-like object is required, not 'str'
在#105编码成bytes即可
fobj.write(self._html().encode('utf8'))
修改后的_html
和plot
函数
def _html(self):
with open(os.path.join(os.path.dirname(__file__), 'plot.j2'), encoding='utf8') as f:
template = f.read()
return template.replace('{{ opt }}', json.dumps(self.json, indent=4))
def plot(self, persist=True):
"""
Plot into html file
:param persist: persist output html to disk
"""
with tempfile.NamedTemporaryFile(suffix='.html', delete=not persist) as fobj:
fobj.write(self._html().encode('utf8'))
fobj.flush()
webbrowser.open('file://' + os.path.realpath(fobj.name))
persist or raw_input('Press enter for continue')
照这样改了,还是会报错。UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 250: illegal multibyte sequence