[Tutor] Creating an Identifier or Object Name from a String?
by Dan Shafer other posts by this author
Jun 11 2002 8:02AM messages near this date
RE: [Tutor] retreiving email file attachments
|
Re: [Tutor] Creating an Identifier or Object Name from a String?
I have a need to refer to a number of objects which have been named field1,
field2, field3, etc. I want to set a property in each object in a loop.
I thought this should work:
for ct in range(1,4):
objToUpdate = "field" + str(ct)
objToChange = eval(objToUpdate) # seems like it should produce
"field1" first time through the loop, etc.
objToChange.text = inputList[ct] #inputList is generated prior to
entering the loop and is a list of string values
This produces an error indicating that string objects don't have a text
attribute. So clearly objToChange is still a string at this point.
I suspect this is tricky but if someone could help....
Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Dan Shafer
Gregor Lingl
Dan Shafer
Danny Yoo
Dan Shafer
|