diff --git a/examples/core/appconfig.py b/examples/core/appconfig.py index a6b41c1..c2e4d26 100644 --- a/examples/core/appconfig.py +++ b/examples/core/appconfig.py @@ -30,8 +30,6 @@ When the config attribute of an Application is updated, it will fire all of the trait's events for all of the config=True attributes. """ -import sys - from IPython.config.configurable import Configurable from IPython.config.application import Application from IPython.utils.traitlets import ( @@ -87,8 +85,8 @@ class MyApp(Application): self.init_bar() def start(self): - print "app.config:" - print self.config + print("app.config:") + print(self.config) def main(): diff --git a/examples/core/ipython-get-history.py b/examples/core/ipython-get-history.py index d6d51ec..3768aea 100755 --- a/examples/core/ipython-get-history.py +++ b/examples/core/ipython-get-history.py @@ -17,7 +17,6 @@ to build much more flexible and powerful tools to browse and pull from the history database. """ import sys -import codecs from IPython.core.history import HistoryAccessor @@ -34,5 +33,5 @@ dest.write("# coding: utf-8\n") hist = HistoryAccessor() for session, lineno, cell in hist.get_range(session=session_number, raw=raw): - # To use this in Python 3, remove the .encode() here: - dest.write(cell.encode('utf-8') + '\n') + cell = cell.encode('utf-8') # This line is only needed on Python 2. + dest.write(cell + '\n') diff --git a/examples/inprocess/embedded_qtconsole.py b/examples/inprocess/embedded_qtconsole.py index 5fe6a1a..3fc6629 100644 --- a/examples/inprocess/embedded_qtconsole.py +++ b/examples/inprocess/embedded_qtconsole.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os from IPython.qt.console.rich_ipython_widget import RichIPythonWidget @@ -6,7 +7,7 @@ from IPython.lib import guisupport def print_process_id(): - print 'Process ID is:', os.getpid() + print('Process ID is:', os.getpid()) def main(): diff --git a/examples/inprocess/embedded_terminal.py b/examples/inprocess/embedded_terminal.py index e42105b..a295c0a 100644 --- a/examples/inprocess/embedded_terminal.py +++ b/examples/inprocess/embedded_terminal.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os from IPython.kernel.inprocess import InProcessKernelManager @@ -5,7 +6,7 @@ from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShel def print_process_id(): - print 'Process ID is:', os.getpid() + print('Process ID is:', os.getpid()) def main(): diff --git a/examples/lib/gui-qt.py b/examples/lib/gui-qt.py index 13e4d27..abb6fb8 100755 --- a/examples/lib/gui-qt.py +++ b/examples/lib/gui-qt.py @@ -10,7 +10,6 @@ In [6]: %run gui-qt.py Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/ """ -import sys from PyQt4 import QtGui, QtCore class SimpleWindow(QtGui.QWidget): diff --git a/examples/lib/gui-tk.py b/examples/lib/gui-tk.py index beb8677..681e003 100755 --- a/examples/lib/gui-tk.py +++ b/examples/lib/gui-tk.py @@ -8,7 +8,10 @@ In [5]: %gui tk In [6]: %run gui-tk.py """ -from Tkinter import * +try: + from tkinter import * # Python 3 +except ImportError: + from Tkinter import * # Python 2 class MyApp: diff --git a/examples/lib/internal_ipkernel.py b/examples/lib/internal_ipkernel.py index 862bae2..d3ee57c 100644 --- a/examples/lib/internal_ipkernel.py +++ b/examples/lib/internal_ipkernel.py @@ -2,7 +2,6 @@ # Imports #----------------------------------------------------------------------------- -import subprocess import sys from IPython.lib.kernel import connect_qtconsole @@ -42,7 +41,7 @@ class InternalIPKernel(object): def print_namespace(self, evt=None): print("\n***Variables in User namespace***") - for k, v in self.namespace.iteritems(): + for k, v in self.namespace.items(): if k not in self._init_keys and not k.startswith('_'): print('%s -> %r' % (k, v)) sys.stdout.flush()