Help with Dictionaries and Classes requested please.

special_dragonfly Dominic at PLEASEASK.co.uk
Thu Aug 9 04:40:03 EDT 2007


"special_dragonfly" <Dominic at PLEASEASK.co.uk> wrote in message 
news:46bacae3$0$89254$7b0f0fd3 at mistral.news.newnet.co.uk...
> Hello,
> I'm new to this group, I've read through the subject of a lot of the group
> but can't find anything relevant. Perhaps my question is too basic but I'm
> still stuck.
> Classes and Dictionaries.
> If I have a dictionary, how do I instantiate many instances of a class per
> dictionary key? Either at run-time or dynamically.
> Can anyone help me please?
> Thank you
> Dominic
>
>

I've managed to solve the problem, I really was just being a dunce. Here's 
how incase anyone is wondering:

class MyClass:
    def __init__(self):
        name=""
dict={}
dict[0]=[]
dict[0].append(MyClass())
dict[0][0].name="Hello"
print dict[0][0].name

I'm sorry if I've wasted anyones time, although if there's a better way of 
doing the above I'd still be interested to know.
Dominic





More information about the Python-list mailing list