更新时间:2023-09-18 14:05:16
在Python中,访问对象属性语法是
< object instance>。< attribute_name>
在您的情况下,[index]。
您还可以使用for循环迭代
for< ; OBJ>在< object_list>中:
< obj>。< attribute_name>
希望有所帮助
In other programming languages, to access attributes in of a class instance you just do:
print(Object.Attr)
and you do so in python as well, but how exactly you get a certain attribute at a certain index in a list of objects, normally i'd do this:
ListObj[i].attr
but the object is in a list. I want to access a specific index inside the list and pull the object attributes inside that index.
In Python, to access object attribute the syntax is
<object instance>.<attribute_name>
In your case, [index].
As Paul said, use dir(<object_instance>[index])
to get all attribute, methods associated object instance.
You can also use for loop to iterate over
for <obj> in <object_list>:
<obj>.<attribute_name>
Hope it helps