File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
2
- def start_python_console (namespace = None , noipython = False ):
2
+ def start_python_console (namespace = None , noipython = False , banner = '' ):
3
3
"""Start Python console binded to the given namespace. If IPython is
4
4
available, an IPython console will be started instead, unless `noipython`
5
5
is True. Also, tab completion will be used on Unix systems.
6
6
"""
7
7
if namespace is None :
8
8
namespace = {}
9
+
9
10
try :
10
11
try : # use IPython if available
11
12
if noipython :
12
- raise ImportError
13
- import IPython
13
+ raise ImportError ()
14
+
14
15
try :
15
- IPython .embed (user_ns = namespace )
16
- except AttributeError :
17
- shell = IPython .Shell .IPShellEmbed (argv = [], user_ns = namespace )
18
- shell ()
16
+ from IPython .frontend .terminal .embed import InteractiveShellEmbed
17
+ sh = InteractiveShellEmbed (banner1 = banner )
18
+ except ImportError :
19
+ from IPython .Shell import IPShellEmbed
20
+ sh = IPShellEmbed (banner = banner )
21
+
22
+ sh (global_ns = {}, local_ns = namespace )
19
23
except ImportError :
20
24
import code
21
25
try : # readline module is only available on unix systems
@@ -25,6 +29,6 @@ def start_python_console(namespace=None, noipython=False):
25
29
else :
26
30
import rlcompleter
27
31
readline .parse_and_bind ("tab:complete" )
28
- code .interact (banner = '' , local = namespace )
32
+ code .interact (banner = banner , local = namespace )
29
33
except SystemExit : # raised when using exit() in python code.interact
30
34
pass
You can’t perform that action at this time.
0 commit comments