Re: [Tutor] Dynamically named objects

2007-12-28 Thread Chris Fuller
You might find a dictionary useful. Each element in a dictionary is associated with a "key", which can be a string. objectlist = {} o = eval("class1" + "()") objectlist["object1"] = o o.method("hello world") Also, try to avoid using eval(), it usually makes troubleshooting and maintenance hard

Re: [Tutor] Dynamically named objects

2007-12-28 Thread Marc Tompkins
Here's the same thing with a list instead of a dictionary: #=== class thingy(): example = "Just testing - " def __init__(self, num): self.example = self.example + str(num) thang = [] for x in range(1,4): thang.append(thingy(x)) for item,

Re: [Tutor] Dynamically named objects

2007-12-28 Thread Marc Tompkins
Sorry, meant to respond to the list, not just the OP... -- Forwarded message -- From: Marc Tompkins <[EMAIL PROTECTED]> Date: Dec 28, 2007 12:13 AM Subject: Re: [Tutor] Dynamically named objects To: Michael Bernhard Arp Sørensen <[EMAIL PROTECTED]> I don't think

[Tutor] Dynamically named objects

2007-12-27 Thread Michael Bernhard Arp Sørensen
Hi there. I need to instantiate objects on the fly and put the in a list/dict for later use. I was thinking of this: objectlist = [] newobjectname = "object1" classname = "class1" + "()" objectlist.append(newobjectname = eval(classname) ) objectlist[0].method("hello world") Can this be done? If