pythonpython-3.xinspect

inspect for functions starting _


I looking at a functions from pyasl module.

from PyAstronomy import pyasl
import inspect
print(inspect.getsource(pyasl.get_lagrange_1))

which shows that the function returns:

return _get_lagrange_123(q, eps, 1-eps, getdlrp)

How to see the function starting with _, please?


Solution

  • Since it has a leading _, you need to import it explicitly and then inspect it. From the github repo, it seems that _get_lagrange_123 is defined in src/pyasl/asl/aslExt_1/roche.py, so you might be able to import it using

    from PyAstronomy.pyasl.asl.aslExt_1.roche import _get_lagrange_123
    print(inspect.getsource(_get_lagrange_123))
    

    Although I don't have this library PyAstronomy so I can't check it. In any case, you first need to find where the function _get_lagrange_123 is defined and then import the function from the module explicitly.