strings question

Andrew Koenig ark at acm.org
Sat Mar 13 00:26:19 EST 2004


"Faheem Mitha" <faheem at email.unc.edu> wrote in message
news:slrnc53uq9.2lu.faheem at Chrestomanci.home.earth...

> If I am given two strings, named foo and bar, what is the most elegant
> way to create a string object whose name is the value of foo and whose
> value is the value of bar?

The most elegant way might be to avoid altogether the notion of computing
variable names and use a dict instead.  It is unlikely that you really want
to be able to comput a variable name on the fly, because what happens if the
resulting variable happens to clash with a name that you are already using?

If you could say a little more about your application, perhaps we could tell
you more.





More information about the Python-list mailing list