Skip to content

Commit

Permalink
Python Console: Fix error when calling os.system in Python 3
Browse files Browse the repository at this point in the history
Fixes #2452
  • Loading branch information
ccordoba12 committed Jun 3, 2015
1 parent 658bb12 commit 3efba61
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions spyderlib/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3efba61

Please sign in to comment.