Примечание: это не дубликат AttributeError: тип объекта не имеет атрибута . Я пытаюсь написать текстовое приключение.
class place(object):
def __init__(self):
super(place, self).__init__()
self.directions = {
"N":None,
"S":None,
"E":None,
"W":None,
"NE":None,
"NW":None,
"SE":None,
"SW":None
}
def add_directions(self, *args): #There's a problem with putting *args because it takes self as string
#I'm sure there is a more elegant way to do this
for direction in args:
for key in self.directions:
self.directions[key] = direction
print(self)
place()
place.add_directions(place, "The Dark Room")
Я хочу sh добавить «Темную комнату» в переменную класса «self.directions». Однако всякий раз, когда я делаю это, они выдают такую ошибку:
"C:\Program Files (x86)\Python38-32\python.exe" "C:/Users/samue/Documents/School/Y3 2020/Computer Science/Python/TextAdventure/The Dark Asylum.py"
Traceback (most recent call last):
File "C:/Users/samue/Documents/School/Y3 2020/Computer Science/Python/TextAdventure/The Dark Asylum.py", line 25, in <module>
place.add_directions(place, "No")
File "C:/Users/samue/Documents/School/Y3 2020/Computer Science/Python/TextAdventure/The Dark Asylum.py", line 20, in add_directions
for key in self.directions:
AttributeError: type object 'place' has no attribute 'directions'
Я знаю, что мое понимание объектов не так уж и хорошо, но кто-то может помочь мне назначить отдельные направления в строке каждому ключу в переменной класса self.directions
? Что-то не так с *args
в функции add_directions
?