Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Equivalent of TCL's "subst" ?

Reply
Thread Tools

Equivalent of TCL's "subst" ?

 
 
gamename
Guest
Posts: n/a
 
      11-13-2007
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

 
Reply With Quote
 
 
 
 
Steven Bethard
Guest
Posts: n/a
 
      11-13-2007
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
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      11-14-2007
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
 
Reply With Quote
 
Loic Mahe
Guest
Posts: n/a
 
      11-14-2007
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
 
Reply With Quote
 
gamename
Guest
Posts: n/a
 
      11-17-2007
> >>> foobar = "HI!"
> >>> x = 'foo'
> >>> y = 'bar'
> >>> print eval(x+y)

> HI!


Great! Thanks.
-T
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning:Xst:382 - Register A is equivalent to B mag VHDL 1 05-19-2005 05:10 PM
instancename of current entity/architecture -- equivalent to C++ this??? Eric Peers VHDL 2 11-18-2004 05:23 PM
VHDL equivalent of verilog trireg Sanjeev VHDL 4 07-23-2004 09:55 AM
equivalent types in different packages Lolo VHDL 3 09-22-2003 03:23 PM
Re: Image Scanning - TWAIN equivalent Brendan Duffy ASP .Net 0 07-24-2003 08:29 AM



Advertisments