[Tutor] Getting an object's attributes

mhw at doctors.net.uk mhw at doctors.net.uk
Sat Jun 26 10:39:29 CEST 2010

Dear Tutors,

I have an object to which I dynamically add attributes. My question is how I can inspect and display them at run-time?

Class a():

Obj1 = a()

Obj1.name = "Bob"
Obj1.age = 45

dir(a) returns a tuple which contains name and age, but also other things (includings methods, etc.) I could filter this tuple (checking for callable(), etc.)  but I just wondered if there was an existing way of getting just name and age.


Sent from my BlackBerry® wireless device

More information about the Tutor mailing list