diff --git a/.gitignore b/.gitignore index e02f70a..e7bd8bb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ venv/ *.rdb coverage.xml htmlcov/ +.idea/ \ No newline at end of file diff --git a/echarts/__init__.py b/echarts/__init__.py index 4d1683b..ab6b6de 100644 --- a/echarts/__init__.py +++ b/echarts/__init__.py @@ -15,6 +15,7 @@ import logging import tempfile import webbrowser +import codecs from .option import Base from .option import Axis, Legend, Series, Tooltip, Toolbox, VisualMap from .datastructure import * @@ -91,7 +92,7 @@ def json(self): return json def _html(self): - with open(os.path.join(os.path.dirname(__file__), 'plot.j2')) as f: + with codecs.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)) @@ -102,7 +103,7 @@ def plot(self, persist=True): :param persist: persist output html to disk """ with tempfile.NamedTemporaryFile(suffix='.html', delete=not persist) as fobj: - fobj.write(self._html()) + fobj.write(self._html().encode('utf8')) fobj.flush() webbrowser.open('file://' + os.path.realpath(fobj.name)) persist or raw_input('Press enter for continue')