ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
[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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved