Ok I know you can use the dir() method to list everything in a module, but is there any way to see only the functions that are defined in that module? For example, assume my module looks like this:
from datetime import date, datetime
def test():
return "This is a real method"
Even if i use inspect() to filter out the builtins, I'm still left with anything that was imported. E.g I'll see:
['date', 'datetime', 'test']
Is there any way to exclude imports? Or another way to find out what's defined in a module?
Every class in python has a
__module__
attribute. You can use its value to perform filtering. Take a look at example 6.14 in dive into pythonAre you looking for something like this?
EDIT: Changed variable names from 'meth' to 'func' to avoid confusion (we're dealing with functions, not methods, here).
You can check
__module__
attribute of the function in question. I say "function" because a method belongs to a class usually ;-).BTW, a class actually also has
__module__
attribute.the python inspect module is probably what you're looking for here.
How about the following: