[Tutor] names and variables

Jim Morcombe jmorcombe at westnet.com.au
Wed Aug 20 11:30:37 CEST 2008

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

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

Now, I have a variable "myAttribute" and set its value to "colour" by 
    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

More information about the Tutor mailing list