Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython forward slash documentation

Tags:

python

ipython

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.

like image 318
leewz Avatar asked Sep 18 '26 06:09

leewz


1 Answers

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

like image 125
Padraic Cunningham Avatar answered Sep 20 '26 20:09

Padraic Cunningham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!