I have an object called "myObject" with an attribute called "colour".

If  I type:
   print myObject.colour
then python prints:
    red

Now, I have a variable "myAttribute" and set its value to "colour" by typing:
   myAttribute = "colour"

I want to have a line of code:  something like this:
   print myObject.myAttribute
and have Python interpret it as meaning "print myObject.colour" and hence print "red"


Can this be done?  If so, how?

Jim Morcombe



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to