Jharwood
Jharwood

Reputation: 1056

Finding other functions within a Python module

I'm working on a function that automatically takes some code I've written and creates checksums in python to be uploaded along with the source code.

The issue is I need to dynamically discover other functions within the same module that I'm currently in.

This is so we can continue to write more code and have it automatically updated.

TL:DR; Making An Automatic Source Code Checksum and Upload Tool For Functions In Same Source File. How do I Locate All The Other Functions?

eg:

def func1(y):
    some random stuff.....
    return x

def autochecksum():
    for func in module:
        checksum = md5(inspect.code(func)).hexdigest
        othermodule.upload(inspect.code(func), checksum)

Closest I Could get was (pure fluke all the function names started with get_):

def update_jms_directory():
    import appdata.transfer.uploads as uploads
    for function in dir(uploads):
        if function.startswith("get_"):
            package_function()

Upvotes: 0

Views: 86

Answers (1)

EEP
EEP

Reputation: 725

Check out the dir function, http://docs.python.org/tutorial/modules.html#the-dir-function

This gives you the ability to view a sorted list of all the names a module defines, this should be a good starting place.

Upvotes: 3

Related Questions