Unbound Method With Instance As First Argument Got String But Requires Something Else
#Maps.py class Maps(object): def __init__(self): self.animals = [] self.currently_occupied = {} def add_animal(self, name): self.animals.append(na
Solution 1:
You need an instance of Maps, not the Maps class:
maps.Maps.add_animal("Fred") # gives error
mymap = maps.Map()
mymap.add_animal("Fred") # should work
So you should either have a mymap attribute on the Animal class, per Animal instance or as a global object (whatever works best for your case).
Solution 2:
You're calling an unbound method, meaning you're accessing a method from a class itself, and not through an instance (so Python doesn't know which instance should be used as self
). This code shouldn't give that error as shown, but I assume you're doing something like
maps.Maps.add_animal(rbt)
It's not clear what you're trying to do, or I'd offer a suggestion as to how to fix it.
Post a Comment for "Unbound Method With Instance As First Argument Got String But Requires Something Else"