3

I accidentally discovered this feature in IPython:

In [126]: def blah(): return 5

In [127]: /blah
Out[127]: 5

In [128]: /range 5 2 4
Out[128]: range(5, 2, 4)

In [133]: /int '100' base=16
Out[133]: 256

A line starting with a forward slash will have commas and function call parens automatically inserted.

Where do I find out more? I can't seem to find the docs for it.

leewz
  • 3,201
  • 1
  • 18
  • 38
  • No, but I knew about `_` and `Out[133]`. Thanks. – leewz Feb 27 '15 at 20:41
  • Why is `5` the output of `/ 5`? – fepegar Nov 21 '19 at 00:16
  • 1
    @fepegar It looks like putting a space after the slash will make it do nothing to the argument. `/ 1+2` returns `3`. `/ 1 2 3` returns `(1,2,3)`. I guess if `/f a b c` means `f(a,b,c)`, then `/ a b c` turns into `(a,b,c)` (nothing, instead of function name). – leewz Nov 21 '19 at 18:33

1 Answers1

4

If you type ? in ipython you will get the builtin documentation:

 You can force auto-parentheses by using '/' as the first character
     of a line.  For example::

          In [1]: /globals             # becomes 'globals()'

     Note that the '/' MUST be the first character on the line!  This
     won't work::

          In [2]: print /globals    # syntax error

     In most cases the automatic algorithm should work, so you should
     rarely need to explicitly invoke /. One notable exception is if you
     are trying to call a function with a list of tuples as arguments (the
     parenthesis will confuse IPython)::

          In [1]: zip (1,2,3),(4,5,6)  # won't work

     but this will work::

          In [2]: /zip (1,2,3),(4,5,6)
          ------> zip ((1,2,3),(4,5,6))
          Out[2]= [(1, 4), (2, 5), (3, 6)]

     IPython tells you that it has altered your command line by
     displaying the new command line preceded by -->.  e.g.::

          In [18]: callable list
          -------> callable (list)

The relevant docs page which includes other features.

There is a nice list taken from here of most basic features:

enter image description here

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • I knew I saw something about auto-parens before, but I couldn't find that page because it doesn't say "slash" on it. I also just learned of `,`/`;` and the search prompt Ctrl+R from the `?` docs. – leewz Feb 27 '15 at 20:54
  • @leewangzhong, unless you know the actual term it is not easy to find as the ipython docs are pretty comprehensive. – Padraic Cunningham Feb 27 '15 at 20:55
  • Yeah discoverability is a bit weak. I'd be very glad to see "what are your best Ipython commands and tricks" - but I think that would be off-topic for Stackoverflow? (ref: http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118) – user3467349 Feb 27 '15 at 21:06