By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Equivalent of TCL's "subst" ?

P: n/a
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

Nov 13 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
gamename wrote:
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
Nov 13 '07 #2

P: n/a
gamename wrote:
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
Nov 14 '07 #3

P: n/a
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:
>>foobar = "HI!"
x = 'foo'
y = 'bar'
print eval(x+y)
HI!

Loic
Nov 14 '07 #4

P: n/a
>>foobar = "HI!"
>>x = 'foo'
>>y = 'bar'
>>print eval(x+y)
HI!
Great! Thanks.
-T
Nov 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.