##// END OF EJS Templates
Improve Python 3 compatibility for example scripts.
Thomas Kluyver -
Show More
@@ -30,8 +30,6 b' When the config attribute of an Application is updated, it will fire all of'
30 30 the trait's events for all of the config=True attributes.
31 31 """
32 32
33 import sys
34
35 33 from IPython.config.configurable import Configurable
36 34 from IPython.config.application import Application
37 35 from IPython.utils.traitlets import (
@@ -87,8 +85,8 b' class MyApp(Application):'
87 85 self.init_bar()
88 86
89 87 def start(self):
90 print "app.config:"
91 print self.config
88 print("app.config:")
89 print(self.config)
92 90
93 91
94 92 def main():
@@ -17,7 +17,6 b' to build much more flexible and powerful tools to browse and pull from the'
17 17 history database.
18 18 """
19 19 import sys
20 import codecs
21 20
22 21 from IPython.core.history import HistoryAccessor
23 22
@@ -34,5 +33,5 b' dest.write("# coding: utf-8\\n")'
34 33 hist = HistoryAccessor()
35 34
36 35 for session, lineno, cell in hist.get_range(session=session_number, raw=raw):
37 # To use this in Python 3, remove the .encode() here:
38 dest.write(cell.encode('utf-8') + '\n')
36 cell = cell.encode('utf-8') # This line is only needed on Python 2.
37 dest.write(cell + '\n')
@@ -1,3 +1,4 b''
1 from __future__ import print_function
1 2 import os
2 3
3 4 from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
@@ -6,7 +7,7 b' from IPython.lib import guisupport'
6 7
7 8
8 9 def print_process_id():
9 print 'Process ID is:', os.getpid()
10 print('Process ID is:', os.getpid())
10 11
11 12
12 13 def main():
@@ -1,3 +1,4 b''
1 from __future__ import print_function
1 2 import os
2 3
3 4 from IPython.kernel.inprocess import InProcessKernelManager
@@ -5,7 +6,7 b' from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShel'
5 6
6 7
7 8 def print_process_id():
8 print 'Process ID is:', os.getpid()
9 print('Process ID is:', os.getpid())
9 10
10 11
11 12 def main():
@@ -10,7 +10,6 b' In [6]: %run gui-qt.py'
10 10 Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/
11 11 """
12 12
13 import sys
14 13 from PyQt4 import QtGui, QtCore
15 14
16 15 class SimpleWindow(QtGui.QWidget):
@@ -8,7 +8,10 b' In [5]: %gui tk'
8 8 In [6]: %run gui-tk.py
9 9 """
10 10
11 from Tkinter import *
11 try:
12 from tkinter import * # Python 3
13 except ImportError:
14 from Tkinter import * # Python 2
12 15
13 16 class MyApp:
14 17
@@ -2,7 +2,6 b''
2 2 # Imports
3 3 #-----------------------------------------------------------------------------
4 4
5 import subprocess
6 5 import sys
7 6
8 7 from IPython.lib.kernel import connect_qtconsole
@@ -42,7 +41,7 b' class InternalIPKernel(object):'
42 41
43 42 def print_namespace(self, evt=None):
44 43 print("\n***Variables in User namespace***")
45 for k, v in self.namespace.iteritems():
44 for k, v in self.namespace.items():
46 45 if k not in self._init_keys and not k.startswith('_'):
47 46 print('%s -> %r' % (k, v))
48 47 sys.stdout.flush()
General Comments 0
You need to be logged in to leave comments. Login now