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