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, value in enumerate(thang):
    print item, value.example
#============================================


On Dec 27, 2007 11:44 PM, Michael Bernhard Arp Sørensen <
[EMAIL PROTECTED]> wrote:

> 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 not, is there a work around or some design pattern
> for this situation?
>
> --
> Venlig hilsen/Kind regards
>
> Michael B. Arp Sørensen
> Programmør / BOFH
>
> I am /root and if you see me laughing you better have a backup.
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
www.fsrtechnologies.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to