473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Equivalent of TCL's "subst" ?

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
4 2075
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
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
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
>>foobar = "HI!"
>>x = 'foo'
>>y = 'bar'
>>print eval(x+y)
HI!
Great! Thanks.
-T
Nov 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
I need to find a PHP equivalent to a very familiar TCL command "subst" (see http://www.hume.com/html84/mann/subst.html ). This command will take a string and evaluate anything TCL inside of it...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.