天天看點

python-内省工具__name__ and __dict__代碼中使用的類

代碼中使用的類

>>> from person import Person

>>> bob = Person('Bob Smith')

>>> print(bob)

[Persion:Bob Smith,0]

>>> bob.__class__

<class 'person.Person'>

>>> bob.__class__.__name__

'Person'

>>> list(bob.__dict__.keys())

['name', 'job', 'pay']

>>> for key in bob.__dict__:

print(key,"=>",getattr(bob,key))

name => Bob Smith

job => None

pay => 0