Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I inspect one specific object in IPython

The command whos and linemagic %whos are available in IPython, but are not part of standard Python. Both of these will list current variables, along with some information about them. You can specify a type to filter by, e.g.

Variable   Type    Data/Info
a          list    n=3
b          int     2
c          str     hello

whos list
Variable   Type    Data/Info
a          list    n=3

The related command who or linemagic %who will produce a short list, showing the variable names only:


who list

To Inspect a specific variable the ? is what you are looking for:


Type:        list
String form: [1, 2, 3]
Length:      3
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

If you want even more information about an object, such as a function. You can use two ? in the form word?? to get the complete object help. For example, to get the complete documentation for the type int you would use:

Type:        type
String form: type 'int'>
Namespace:   Python builtin
int(x=0) -> int or long
int(x, base=10) -> int or long

Convert a number or string to an integer, or return 0 if no arguments
are given.  If x is floating point, the conversion truncates towards zero.
If x is outside the integer range, the function returns a long instead.

If x is not a number or if base is given, then x must be a string or
Unicode object representing an integer literal in the given base.  The
literal can be preceded by '+' or '-' and be surrounded by whitespace.
The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
interpret the base from the string as an integer literal.
>>> int('0b100', base=0)

This post first appeared on Martin Fitzpatrick – Python Coder, Postgraduate, please read the originial post: here

Share the post

How do I inspect one specific object in IPython


Subscribe to Martin Fitzpatrick – Python Coder, Postgraduate

Get updates delivered right to your inbox!

Thank you for your subscription