list - Please explain this python "for" statement: methodList = [method for method in dir(object) if callable(getattr(object, method))] -
i trying use introspection list of objects functions. have been reading "dive python", , aforementioned statement:
methodlist = [method method in dir(object) if callable(getattr(object, method))]
does trick. problem is, have no idea doing. me looks extreme shorthand looping, testing, , adding elements list. if correct, part of statement what?!
in other words, can 1 please translate english.
another way @ this:
methodlist = [] method in dir(object): # every attribute in object # note methods considered attributes if callable(getattr(object, method)) # callable? methodlist.append(method) return methodlist
the construct list comprehension filter.
see: dir()
, callable()
, getattr()
, list comprehensions
Comments
Post a Comment