Discussion On
You Should Change Your Python Shell

by in Books & Tools

6 Comments

  1. Iven
    Tuesday, December 1740, 2013

    While IPython is powerful, it’s not user-friendly. Try bpython.

    Reply
    • flying sheep
      Thursday, December 1959, 2013

      what? it’s very user friendly. partly because of the features mentioned by OP (autoreload, history, autocomplete), partly because of the shortcut magics like %pylab.

      i don’t know about anything that bpython does better, and you didn’t even name anything, so how do you think you could convince somebody of anything?

      Reply
  2. aweraw
    Thursday, December 1951, 2013

    Why bother typing exit when a single keystroke will do? Ctrl-D under linux/unix-like OS’s, or Ctrl-Z under windows.

    Reply
  3. Paul Ivanov
    Friday, December 2028, 2013

    thanks for plugging IPython. One killer feature you haven’t mentioned is the

    ?

    (question mark). It’s much easier to type that at the end of a function name to get the docstring for it. Try it by typing

    In [1]: import os.path
    
    In [2]: os.path?
    Type:       module
    String Form:
    File:       /usr/lib/python2.7/posixpath.py
    Docstring:
    Common operations on Posix pathnames.
    
    Instead of importing this module directly, import os and refer to
    this module as os.path.  The "os.path" name is an alias for this
    module on Posix systems; on other systems (e.g. Mac, Windows),
    os.path provides the same operations in a manner specific to that
    platform, and is an alias to another module (e.g. macpath, ntpath).
    
    Some of this can actually be useful on non-Posix systems too, e.g.
    for manipulation of the pathname component of URLs.
    

    Now, if it’s a pure-python module or function, you can actually type in two question marks, to get the source code:

    
    Type:       module
    String Form:
    File:       /usr/lib/python2.7/posixpath.py
    Source:
    """Common operations on Posix pathnames.
    
    Instead of importing this module directly, import os and refer to
    this module as os.path.  The "os.path" name is an alias for this
    module on Posix systems; on other systems (e.g. Mac, Windows),
    os.path provides the same operations in a manner specific to that
    platform, and is an alias to another module (e.g. macpath, ntpath).
    
    Some of this can actually be useful on non-Posix systems too, e.g.
    for manipulation of the pathname component of URLs.
    """
    
    import os
    import sys
    import stat
    import genericpath
    import warnings
    from genericpath import *
    
    try:
        _unicode = unicode
    ...
    

    Also, as a quick note:

    %lprun

    is provided by line_profiler by Robert Kern, and

    %memit

    and

    %mprun are provided by memory_profiler by Fabian Pedrogosa and and Philippe Gervais, so you need to pip install those separately.
    Reply
  4. Sid
    Saturday, December 2811, 2013

    If you are on windows, try enthought canopy that packages an editor, IPython, package manager and a document viewer.

    Reply
  5. Denilson
    Wednesday, January 141, 2014

    Instead of typing “exit”, we can just press Ctrl+D to send an EOF, which will quit most kinds of shells (including bash and Python).

    Reply

Leave a Reply