File: console.py

package info (click to toggle)
python-scrapy 0.14.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,064 kB
  • sloc: python: 19,468; xml: 199; sh: 134; makefile: 67
file content (30 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

def start_python_console(namespace=None, noipython=False):
    """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
            try:
                IPython.embed(user_ns=namespace)
            except AttributeError:
                shell = IPython.Shell.IPShellEmbed(argv=[], user_ns=namespace)
                shell()
        except ImportError:
            import code
            try: # readline module is only available on unix systems
                import readline
            except ImportError:
                pass
            else:
                import rlcompleter
                readline.parse_and_bind("tab:complete")
            code.interact(banner='', local=namespace)
    except SystemExit: # raised when using exit() in python code.interact
        pass