Reputation: 51
sample_list = []
for attribute in dir(sample_list):
if callable(attribute):
print(attribute)
I'm writing this code to find out what attributes of sample_list
are callable. I know the list
class has callable attributes like append
and pop
but none of them seem to show up. why's this?
Upvotes: 1
Views: 350
Reputation: 59240
attribute
is a string. A string isn't callable. You're missing getattr(sample_list, attribute)
.
sample_list = []
for attribute in dir(sample_list):
value = getattr(sample_list, attribute)
if callable(value):
print(attribute)
Upvotes: 2