Question: Evaluate an string variable's value to a variable

M

Mir Nazim

Just a quick question.

For example I have

Then I do
Now my question is whether something like below is possible and how

PS: In PHP this can be done by a $x->$y. I sure there is some way in
Python also


Thanks in advance.
 
C

Chris Rebert

Just a quick question.

For example I have


Then I do

Now my question is whether something like below is possible and how

print getattr(x, y) #==> Nazim

There are also analogous setattr() and delattr() functions.

Cheers,
Chris
 
M

Mir Nazim

print getattr(x, y) #==> Nazim

There are also analogous setattr() and delattr() functions.

Damn Right.
These functions simply eluded my mind for well 15 minutes

Thanks a lot Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top