faheem at email.unc.edu
Sat Mar 13 18:30:46 CET 2004
On Sat, 13 Mar 2004 05:26:19 GMT, Andrew Koenig <ark at acm.org> wrote:
> "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.
Yes, someone else also suggested a dictionary, and I agree it is the
best way to go. Potential name clashes had not occurred to me till you
mentioned it, though.
I'm trying to produce a list of DNA sequences for further manipulation
with the names and the values of the sequences read from a file into
strings, and so in this case, the value of foo would be the name of
the sequence, and the value of bar would be the value of the sequence.
However, I'll look at what other people have suggested. I am new to
python and so don't even understand the answers, but will read up on
I own one of your books, by the way (Accelerated C++). :-)
Thanks to everyone who replied.
More information about the Python-list