【发布时间】:2014-09-30 22:50:27
【问题描述】:
我有一个对象,我们会说Person
Person 具有以下属性:
name、age、gender
我想遍历Person 的一个实例并打印它的所有值。
我现在正在使用:
Ryan = Person()
for prop in dir(Ryan):
print(i)
打印出来:
name
age
gender
现在,我如何找到这些值?我试过了
for prop in dir(Ryan):
print(Ryan.i) #object has no attribute `i`
【问题讨论】:
标签: python loops properties attributes