Чтобы получить значение атрибута, мне нужно вызвать method.attribute.attribute вместо method.attribute, почему это так? Вызов метода.attribute приводит к адресу памяти. Как / можно изменить мой код, чтобы метод method.attribute работал?
Большинство проблем, связанных с этим центром, касаются вызова print (f) вместо print (f ())
class MyList:
"""stores a list and does other stuff eventualy"""
this_list = []
def __init__(self, *args):
for arg in args:
self.this_list.append(arg)
def print_list(self):
"""prints the atribute:"description" from the stored objects in the list"""
for x in range(len(self.this_list)):
print(MyClassObj(self.this_list[x]).description, sep="\n")
Это код, который должен печатать значение атрибута описание
class MyClassObj:
"""test object to be stores in the "MyList" object."""
def __init__(self, description):
self.description = description
Это объект, который содержит атрибут, который я хочу получить.
class CallList:
"""creates the objects, lists and calls the print method"""
@staticmethod
def main():
test1, test2 = MyClassObj("Test1"), MyClassObj("Test2")
list1 = MyList(test1, test2)
list1.print_list()
Main () вызывается вне вышеуказанных классов.
Я получаю вывод
<__main__.MyClassObj object at 0x007908F0>
<__main__.MyClassObj object at 0x00790910>
Process finished with exit code 0
Если я изменю строку:
print(MyClassObj(self.this_list[x]).description.description, sep="\n")
Я получаю ожидаемый результат:
Test1
Test2
Process finished with exit code 0
Итак, вопрос в том, почему и как я должен изменить свой код?