##// END OF EJS Templates
Use print_function in example-embed
Thomas Kluyver -
Show More
@@ -9,6 +9,7 b' embedding which you can cut and paste in your code once you understand how'
9 things work.
9 things work.
10
10
11 The code in this file is deliberately extra-verbose, meant for learning."""
11 The code in this file is deliberately extra-verbose, meant for learning."""
12 from __future__ import print_function
12
13
13 # The basics to get you going:
14 # The basics to get you going:
14
15
@@ -28,8 +29,8 b' except NameError:'
28 prompt_config.in2_template = ' .\\D.: '
29 prompt_config.in2_template = ' .\\D.: '
29 prompt_config.out_template = 'Out<\\#>: '
30 prompt_config.out_template = 'Out<\\#>: '
30 else:
31 else:
31 print "Running nested copies of IPython."
32 print("Running nested copies of IPython.")
32 print "The prompts for the nested copy have been modified"
33 print("The prompts for the nested copy have been modified")
33 cfg = Config()
34 cfg = Config()
34 nested = 1
35 nested = 1
35
36
@@ -55,7 +56,7 b' if not nested:'
55 ipshell2 = InteractiveShellEmbed(config=cfg,
56 ipshell2 = InteractiveShellEmbed(config=cfg,
56 banner1 = 'Second IPython instance.')
57 banner1 = 'Second IPython instance.')
57
58
58 print '\nHello. This is printed from the main controller program.\n'
59 print('\nHello. This is printed from the main controller program.\n')
59
60
60 # You can then call ipshell() anywhere you need it (with an optional
61 # You can then call ipshell() anywhere you need it (with an optional
61 # message):
62 # message):
@@ -64,7 +65,7 b" ipshell('***Called from top level. '"
64 'Note that if you use %kill_embedded, you can fully deactivate\n'
65 'Note that if you use %kill_embedded, you can fully deactivate\n'
65 'This embedded instance so it will never turn on again')
66 'This embedded instance so it will never turn on again')
66
67
67 print '\nBack in caller program, moving along...\n'
68 print('\nBack in caller program, moving along...\n')
68
69
69 #---------------------------------------------------------------------------
70 #---------------------------------------------------------------------------
70 # More details:
71 # More details:
@@ -101,37 +102,37 b" ipshell.exit_msg = 'Leaving interpreter - New exit_msg'"
101 def foo(m):
102 def foo(m):
102 s = 'spam'
103 s = 'spam'
103 ipshell('***In foo(). Try %whos, or print s or m:')
104 ipshell('***In foo(). Try %whos, or print s or m:')
104 print 'foo says m = ',m
105 print('foo says m = ',m)
105
106
106 def bar(n):
107 def bar(n):
107 s = 'eggs'
108 s = 'eggs'
108 ipshell('***In bar(). Try %whos, or print s or n:')
109 ipshell('***In bar(). Try %whos, or print s or n:')
109 print 'bar says n = ',n
110 print('bar says n = ',n)
110
111
111 # Some calls to the above functions which will trigger IPython:
112 # Some calls to the above functions which will trigger IPython:
112 print 'Main program calling foo("eggs")\n'
113 print('Main program calling foo("eggs")\n')
113 foo('eggs')
114 foo('eggs')
114
115
115 # The shell can be put in 'dummy' mode where calls to it silently return. This
116 # The shell can be put in 'dummy' mode where calls to it silently return. This
116 # allows you, for example, to globally turn off debugging for a program with a
117 # allows you, for example, to globally turn off debugging for a program with a
117 # single call.
118 # single call.
118 ipshell.dummy_mode = True
119 ipshell.dummy_mode = True
119 print '\nTrying to call IPython which is now "dummy":'
120 print('\nTrying to call IPython which is now "dummy":')
120 ipshell()
121 ipshell()
121 print 'Nothing happened...'
122 print('Nothing happened...')
122 # The global 'dummy' mode can still be overridden for a single call
123 # The global 'dummy' mode can still be overridden for a single call
123 print '\nOverriding dummy mode manually:'
124 print('\nOverriding dummy mode manually:')
124 ipshell(dummy=False)
125 ipshell(dummy=False)
125
126
126 # Reactivate the IPython shell
127 # Reactivate the IPython shell
127 ipshell.dummy_mode = False
128 ipshell.dummy_mode = False
128
129
129 print 'You can even have multiple embedded instances:'
130 print('You can even have multiple embedded instances:')
130 ipshell2()
131 ipshell2()
131
132
132 print '\nMain program calling bar("spam")\n'
133 print('\nMain program calling bar("spam")\n')
133 bar('spam')
134 bar('spam')
134
135
135 print 'Main program finished. Bye!'
136 print('Main program finished. Bye!')
136
137
137 #********************** End of file <example-embed.py> ***********************
138 #********************** End of file <example-embed.py> ***********************
General Comments 0
You need to be logged in to leave comments. Login now