I would like to create a list of all the functions used in a code file. For example if we have following code in a file named \'add_random.py\'
`
import
In general, this problem is undecidable, consider for example getattribute(random, "random")()
.
If you want static analysis, the best there is now is jedi
If you accept dynamic solutions, then cover coverage is your best friend. It will show all used functions, rather than only directly referenced though.
Finally you can always roll your own dynamic instrumentation along the lines of:
import random
import logging
class Proxy(object):
def __getattr__(self, name):
logging.debug("tried to use random.%s", name)
return getattribute(_random, name)
_random = random
random = Proxy()