From 165cd2282df69d74f2400b76240d3810b905b7c5 Mon Sep 17 00:00:00 2001 From: Son Hai Nguyen Date: Tue, 21 Nov 2017 14:44:38 +0100 Subject: [PATCH] Fix read/write files with utf-8 - #25 --- ifj2017/ide/core/file_io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ifj2017/ide/core/file_io.py b/ifj2017/ide/core/file_io.py index 7c87967..a7d2729 100644 --- a/ifj2017/ide/core/file_io.py +++ b/ifj2017/ide/core/file_io.py @@ -37,14 +37,14 @@ def write(self, content: str) -> None: if not self._source: return - with open(self._source, "w") as f: - f.write(content) + with open(self._source, "wb") as f: + f.write(bytes(content, encoding='utf-8')) @pyqtSlot(result=str) def read(self) -> str: if not self._source: return "" - with open(self._source, "r") as f: + with open(self._source, "rb") as f: read_data = f.read() - return read_data \ No newline at end of file + return str(read_data, encoding='utf-8') \ No newline at end of file