print all method and property of list object - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: print all method and property of list object (/thread-22041.html) |
print all method and property of list object - engmoh - Oct-26-2019 lst=[1,2,5] d=dir(lst)#content all methon and properties for i in d: print(lst.i)if i run i have AttributeError: 'list' object has no attribute 'i' RE: print all method and property of list object - Gribouillis - Oct-26-2019 Use print(getattr(list, i)) instead of print(list.i) because the name of the attribute is not 'i' but the value of the variable i.
RE: print all method and property of list object - engmoh - Oct-26-2019 thank you very much can i replace "i" to value of "i" immediately without getattr() function RE: print all method and property of list object - Gribouillis - Oct-26-2019 engmoh Wrote:can i replace "i" to value of "i" immediately without getattr() functionNo. There is no special syntax to access an attribute which name is a variable's value. You may regret this but it's one of the many things that make the great consistency of the language and therefore its success. Python's designers prefer function calls over exotic syntactic constructs. RE: print all method and property of list object - engmoh - Oct-26-2019 (Oct-26-2019, 05:04 PM)Gribouillis Wrote: Python's designers prefer function calls over exotic syntactic constructs.thank you for your advice and deceleration |