Search code examples
pythongraph-tool

Finding function declarations in Ubuntu on Python


I have a vaguely defined function of a class Graph of a module I call gt (it is graph-tool). so i declare g = gt.graph() then want to use g.degree_property_map but do not know how. Therefore I want to see where in code g.degree_property_map or in this case just the function, is defined. How can I find that? I'm working on command line on a vm.

Thanks

For reference the library in question is graph-tool - http://projects.skewed.de/graph-tool/

Also I am currently importing it using from graph_tool.all import * . that is of course somewhat of a problem.


Solution

  • If you open interactive python (type python and hit ENTER on the command line), you should be able to run the command help(<graph's module name>), then, under the FILE section of the help documentation that is generated, you should see the absolute path to the code you are interested in.

    For example, I just ran:

    import numpy
    help(numpy)
    
    # Returned documentation containing:
    # FILE
    # /usr/lib/python2.7/dist-packages/numpy/__init__.py
    

    Also,

    import my_module # A module I just created that contains the "Line" class
    help(my_module)
    
    # Returned documentation containing:
    # FILE
    # /home/<my user name>/Programming/Python/my_module.py