Create object name from string value?

Gnarlodious gnarlodious at gmail.com
Thu Jan 21 04:02:49 CET 2010


I want to declare several objects from names in a list:

objects=['object1', 'object2', 'object3', 'object4']
for objectName in objects:
	objectName=classname()

That fails, and so do these:

exec(objectName)=classname()
eval(objectName)=classname()

So how to make an object whose name is the value in the variable?

-- Gnarlie



More information about the Python-list mailing list