Equivalent of TCL's "subst" ?

G

gamename

Hi,

In TCL, you can do things like:
set foobar "HI!"
set x foo
set y bar
subst $$x$y
HI!

Is there a way to do this type of evaluation in python?

TIA,
-T
 
S

Steven Bethard

gamename said:
In TCL, you can do things like:
set foobar "HI!"
set x foo
set y bar
subst $$x$y
HI!

Is there a way to do this type of evaluation in python?

If this is at the outer-most scope, you can use globals()::
>>> foobar = 'HI!'
>>> x = 'foo'
>>> y = 'bar'
>>> globals_dict = globals()
>>> globals_dict[x + y]
'HI!'

That said, why do you think you want to do this?

STeVe
 
L

Larry Bates

gamename said:
Hi,

In TCL, you can do things like:
set foobar "HI!"
set x foo
set y bar
subst $$x$y
HI!

Is there a way to do this type of evaluation in python?

TIA,
-T

myStore={}

myStore['foobar']="HI!"
x='foo'
y='bar'
print myStore[x+y]

-Larry
 
L

Loic Mahe

gamename a écrit :
Hi,

In TCL, you can do things like:
set foobar "HI!"
set x foo
set y bar
subst $$x$y
HI!

Is there a way to do this type of evaluation in python?

TIA,
-T

you can also try using eval:
HI!



Loic
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top