[IPython-user] learn details about a function

John Hunter jdhunter at ace.bsd.uchicago.edu
Sat Jul 2 10:10:09 CDT 2005


>>>>> "Ogz" == Ogz  <comp.ogz at gmail.com> writes:

    Ogz> Is there a way that i can check the local variables values of
    Ogz> a function that is defined and used in the program, in
    Ogz> ipython, and learn which modules or attributes they have,
    Ogz> like if it is takin an object as a parameter, i will wirte
    Ogz> the name and use tab to see what can i do for it?

I think the standard way to use ipython to "look inside" a function,
for example at the values of it's local variable, is to embed an
ipython shell in the function.

def somefunc(x,y):
  z = x*y

  # add these calls to the function before the return
  from IPython.Shell import IPShellEmbed
  ipshell = IPShellEmbed()
  ipshell() # this call anywhere in your program will start IPython 

  return z

Then when you run a script that calls somefunc, it will pop up an
ipython shell and you can inspect x,y,z etc..

JDH




More information about the IPython-user mailing list