I am trying to update an occupants list in the class Place, after setting it with:
places["smith"] = Place( "smith", "This is the Blacksmith's Shop", "grimwo", ("well", "bakery", "mill"), () ) persons["berrol"] = Person("berrol", "bakery", "baker")
The classes are setup as: Person / Place
class Person(object): """ This is the Person object for all people in the village """ def __init__(self, name, location, title): # define initial person values self.name = name self.location = "" self.title = title self.setLocation(name, location) # setup for how this class prints def __str__(self): s = self.name, self.title return s # setup to show the person details def show(self): print self.name, '\t\t', self.location, '\t\t', self.title def setLocation(self, name, location): # define how a person changes location if self.location == "": # call Place.getOccupant to set this location place = location place = places[location] place.getOccupants(name) else: # call Place.remOccupant to remove existing location then set new one # no code in place yet class Place(object): """ This is the Place object for all Places. """ def __init__(self, name, description, owner, targets, occupants): # define initial variables self.name = name self.description = description self.owner = owner self.targets = targets self.occupants = occupants self.status = "" # setup to show this place details def show(self): print self.description if self.name != "well": if self.owner in self.occupants: self.status = "open" print "The", self.name, "is open!" self.showOccupants() else: self.status = "closed" print "We're sorry the", self.name, "is currently closed." else: self.showOccupants() self.showTargets() # setup to show available targets of this place def showTargets(self): if self.targets: print "From here you can go: " for target in self.targets: print "\t", target # setup to show the occupants of this place def showOccupants(self): if self.occupants: print "Currently here are: " for occupant in self.occupants: print "\t", occupant def getOccupants(self, occupant): # define how to add an occupant self.occupants += (occupant, ) def remOccupants(self, occupant): # define how to remove an occupant if occupant in self.occupants: self.occupants.remove(occupant)
I am successful at setting the inital 'occupant,' but when trying to remove someone so that they can be added to another Place, I am receiving the error: AttributeError: 'str' object has no attribute when trying to use the code:
Any help would be appreciated.