On 5/31/2018 3:49 PM, bruceg113...@gmail.com wrote:
> How do I list only the methods I define in a class?
Here's a class with some method, defined in various ways:
>>> class x():
... a=3
... def f():pass
... g = lambda: None
...
>>> l=[v for v in x.__dict__.items()]; print(l)
[('a', 3), ('f', <function x.f at 0x000001DEDD693840>), ('__module__',
'__main__'), ('__dict__', <attribute '__dict__' of 'x' objects>),
('__doc__', None), ('__weakref__', <attribute '__weakref__' of 'x'
objects>)]
>>> import inspect
>>> [(key, value) for key, value in l if inspect.isfunction(i[1])]
[('f', <function x.f at 0x000001DEDD6936A8>), ('g', <function x.<lambda>
at 0x000001DEDD693620>)]
HTH
--
https://mail.python.org/mailman/listinfo/python-list