pretty basic: get variable name from list of strings?

chris
Mon Jul 29 19:47:08 EDT 2002


Thanks Andrew, 

I'll definitely look up how to use dicts.

Will they also help in iterating other "treat string like code"
situations like wxPython object creation, here where I want to create
100 radioboxes?

for j in range(1,100):
	varname = 'self.Box'+str(j)
	varname = wxRadioBox(self, ID_j, name, wxDefaultPos,
wxDefaultSize, TeamList[j], 1, wxRA_SPECIFY_COLS)
	EVT_RADIOBOX(self, ID_j, self.EvtRadioBox_j)

Surely there's a way to have a string like 'FileCount = 6' and tell
python to execute it.  Wait a minute...  execute...

Aha, 
>>> exec('horse = 9')
>>> horse
9

I'll still look into dict for general usefulness...
Chris


On Mon, 29 Jul 2002 22:35:31 GMT, Andrew Koenig <ark at research.att.com>
wrote:


>The first question to answer is why you want to have a whole bunch
>of variable names instead of using a dict.




More information about the Python-list mailing list