Is there a way to ignore imported functions in a python module?
When using the following module module.py:
from inspect import getmembers, isfunction
import foo
def boo():
foo()
def moo():
pass
funcs = [mem[0] for mem in getmembers(module, isfunction)]
funcs equals : ['boo','moo', 'foo']
(including imported function 'foo')
I want funcs to include ['boo', 'moo']
only.
You'll have to test for the __module__
attribute; it is a string naming the full module path:
funcs = [mem[0] for mem in getmembers(module, isfunction)
if mem[1].__module__ == module.__name__]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With