Name: Anonymous 2010-08-29 21:47
I don't normally work with python, but noodling around with it has been fairly easy until I hit this brickwall:
so I make a class, lets say "person". now I make a whole bunch of instances of person. I take each person, and make them as a value inside a dictionary, "people" keyed to zero through n, where n is the number of persons.
Then I put this dictionary inside a new class, lets call it city, so that in any instance of a city I can have this dictionary of persons, with their individual keys.
I made an instance of this hypothetical city class, and tried to call one of these persons through their key, ie exampleCity.people[i], were i is the key, and python spits out at me "instance has no attribute '__getitem__'"
I'm trying to have a for loop run through the city's dictionary of people, but no matter how I try to swing it, python keeps throwing this AttributeError
do I need to define some sort of get and set functions? I thought python keeps attributes as public by default...
so I make a class, lets say "person". now I make a whole bunch of instances of person. I take each person, and make them as a value inside a dictionary, "people" keyed to zero through n, where n is the number of persons.
Then I put this dictionary inside a new class, lets call it city, so that in any instance of a city I can have this dictionary of persons, with their individual keys.
I made an instance of this hypothetical city class, and tried to call one of these persons through their key, ie exampleCity.people[i], were i is the key, and python spits out at me "instance has no attribute '__getitem__'"
I'm trying to have a for loop run through the city's dictionary of people, but no matter how I try to swing it, python keeps throwing this AttributeError
do I need to define some sort of get and set functions? I thought python keeps attributes as public by default...