From 3efba6101e1f341852b483be8a10428df75dbffd Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Wed, 3 Jun 2015 17:57:29 -0500 Subject: [PATCH] Python Console: Fix error when calling os.system in Python 3 Fixes #2452 --- spyderlib/widgets/shell.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/spyderlib/widgets/shell.py b/spyderlib/widgets/shell.py index 97953f91e59..e2257cdfe43 100644 --- a/spyderlib/widgets/shell.py +++ b/spyderlib/widgets/shell.py @@ -11,12 +11,13 @@ # pylint: disable=R0911 # pylint: disable=R0201 +import keyword +import locale import os -import time import os.path as osp import re import sys -import keyword +import time from spyderlib.qt.QtGui import (QMenu, QApplication, QToolTip, QKeySequence, QMessageBox, QTextCursor, QTextCharFormat) @@ -35,7 +36,7 @@ from spyderlib.widgets.mixins import (InspectObjectMixin, TracebackLinksMixin, SaveHistoryMixin) from spyderlib.py3compat import (is_text_string, to_text_string, builtins, - is_string) + is_string, PY3) class ShellBaseWidget(ConsoleBaseWidget, SaveHistoryMixin): @@ -578,7 +579,16 @@ def write(self, text, flush=False, error=False, prompt=False): def flush(self, error=False, prompt=False): """Flush buffer, write text to console""" - text = "".join(self.__buffer) + # Fix for Issue 2452 + if PY3: + try: + text = "".join(self.__buffer) + except TypeError: + text = b"".join(self.__buffer) + text = text.decode( locale.getdefaultlocale()[1] ) + else: + text = "".join(self.__buffer) + self.__buffer = [] self.insert_text(text, at_end=True, error=error, prompt=prompt) QCoreApplication.processEvents()