如何获取Python类中的方法列表?
以下代码打印给定类的方法列表,如下所示
示例
class foo:
def __init__(self):
self.x = x
def bar(self):
pass
def baz(self):
pass
print (type(foo))
import inspect
print(inspect.getmembers(foo, predicate=inspect.ismethod))输出结果
输出是
<type 'classobj'>
[('__init__', <unbound method foo.__init__>), ('bar', <unbound method foo.bar>), ('baz', <unbound method foo.baz>)]热门推荐
10 新年送老师简短祝福语
11 迟到的过年祝福语简短
12 生日寿宴祝福语简短精辟
13 祝福语对联文案简短大气
14 学生祝福语简短古诗句
15 毕业祝福语简短英语小学
16 新婚抖音祝福语简短
17 姨父生日祝福语简短精辟
18 喜庆节的祝福语简短