![](/img/trans.png)
[英]How to find out what function the Python interpreter is calling from callable PyObject?
[英]How do i find out what attributes in a python class are callable?
sample_list = []
for attribute in dir(sample_list):
if callable(attribute):
print(attribute)
我正在编写这段代码来找出sample_list
的哪些属性是可调用的。 我知道list
class 具有诸如append
和pop
之类的可调用属性,但它们似乎都没有出现。 这是为什么
attribute
是一个字符串。 字符串不可调用。 您缺少getattr(sample_list, attribute)
。
sample_list = []
for attribute in dir(sample_list):
value = getattr(sample_list, attribute)
if callable(value):
print(attribute)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.