Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

IPython refuses to update the namespace. fix #396

Daniel Grañaaa6fb7daaacd
diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py
index 1c4449b85..25782d512 100644
--- a/scrapy/utils/console.py
+++ b/scrapy/utils/console.py
@@ -1,21 +1,25 @@
-def start_python_console(namespace=None, noipython=False):
+def start_python_console(namespace=None, noipython=False, banner=''):
"""Start Python console binded to the given namespace. If IPython is
available, an IPython console will be started instead, unless `noipython`
is True. Also, tab completion will be used on Unix systems.
"""
if namespace is None:
namespace = {}
+
try:
try: # use IPython if available
if noipython:
- raise ImportError
- import IPython
+ raise ImportError()
+
try:
- IPython.embed(user_ns=namespace)
- except AttributeError:
- shell = IPython.Shell.IPShellEmbed(argv=[], user_ns=namespace)
- shell()
+ from IPython.frontend.terminal.embed import InteractiveShellEmbed
+ sh = InteractiveShellEmbed(banner1=banner)
+ except ImportError:
+ from IPython.Shell import IPShellEmbed
+ sh = IPShellEmbed(banner=banner)
+
+ sh(global_ns={}, local_ns=namespace)
except ImportError:
import code
try: # readline module is only available on unix systems
@@ -25,6 +29,6 @@ def start_python_console(namespace=None, noipython=False):
else:
import rlcompleter
readline.parse_and_bind("tab:complete")
- code.interact(banner='', local=namespace)
+ code.interact(banner=banner, local=namespace)
except SystemExit: # raised when using exit() in python code.interact
pass