I defined a .py file in this format:
foo.py
def foo1(): pass
def foo2(): pass
def foo3(): pass
I import it from another file:
main.py
from foo import *
# or
import foo
Is it possible list all functions name, e.g. ["foo1", "foo2", "foo3"]
?
Thanks for your help, I made a class for what I want, pls comment if you have suggestion
class GetFuncViaStr(object):
def __init__(self):
d = {}
import foo
for y in [getattr(foo, x) for x in dir(foo)]:
if callable(y):
d[y.__name__] = y
def __getattr__(self, val) :
if not val in self.d :
raise NotImplementedError
else:
return d[val]