On Sun, Dec 21, 2008 at 12:21, Mir Nazim <[email protected]> wrote:

> Hi guys, sorry for the off topic posting, but I know there are a
> couple of python guys on the list, so could not resist asking here
> Just a quick question.
>
> For example I have
>
> >>> class X
> >>> ....pass
>
> Then I do
> >>> x = X()
> >>> x.name = 'Nazim
>
> Now my question is whether something like below is possible and how
> >>> y = 'name'
> >>> print x.y   #  How can x.y can be evaluated to x.name
>

You can use:

print x.__dict__[y]

It will have the same result as:

print x.name


-- 
Aditya Manthramurthy
-- 
ubuntu-in mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-in

Reply via email to