On Wed, Aug 20, 2008 at 5:37 AM, Marc Tompkins <[EMAIL PROTECTED]> wrote:
> print(getattr(myObject, "colour"))
Or, of course,
print getattr(myObject, myAttribute) which is what the OP wanted.
Kent
___
Tutor maillist - Tutor@python.org
http://mail.pyt
On Wed, 2008-08-20 at 11:37 +0200, [EMAIL PROTECTED] wrote:
> Message: 7
> Date: Wed, 20 Aug 2008 17:30:37 +0800
> From: Jim Morcombe <[EMAIL PROTECTED]>
> Subject: [Tutor] names and variables
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Typ
On Wed, Aug 20, 2008 at 2:30 AM, Jim Morcombe <[EMAIL PROTECTED]>wrote:
> 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
> typin
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: