Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python __getitem__ AttributeError

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...

Name: Anonymous 2010-08-29 21:51

You need to provide some code, a description isn't enough because you're most likely doing something else. Don't forget the [code] tags when posting code!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List