Create object name from string value?

Gnarlodious gnarlodious at gmail.com
Wed Jan 20 23:36:33 EST 2010


On Jan 20, 8:31 pm, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> Since (I presume) you are a newcomer to Python, it's best to learn the
> common style <URL:http://www.python.org/dev/peps/pep-0008/>.
Thanks for that.

> This is almost certainly better done with a dictionary. Like so::
>
>     object_names = ['object1', 'object2', 'object3', 'object4']
>     objects = {}
>     for object_name in object_names:
>         objects[object_name] = Class()

And thanks for that too. I see it returns a list of objects, Python is
very cool.

-- Gnarlie




More information about the Python-list mailing list