У меня проблема при повторном использовании функции внутри класса.Я хотел бы получить возвращаемое значение функции, не перезапуская ее каждый раз, когда я ее использую.Каков наилучший способ сделать это внутри класса?
Спасибо!
class Test():
def __init__ (self):
# self.my_list = my_list()
pass
@staticmethod
def my_list():
set_list = [1, 2, 3, 4, 5, 6]
print ('you are not refrencing')
return set_list
@staticmethod
def func_test():
func_list = Test.my_list()
return func_list
@staticmethod
def func_test2():
func_list = Test.my_list()
return func_list
@staticmethod
def print_func():
print Test.my_list()
print Test.func_test()
print Test.func_test2()
return
Test.print_func()
вот мой текущий результат:
you are not referencing
[1, 2, 3, 4, 5, 6]
you are not referencing
[1, 2, 3, 4, 5, 6]
you are not referencing
[1, 2, 3, 4, 5, 6]
Я бы получил этот результатвместо
you are not referencing
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]