I need to clear the list in certain conditions and the variable containing the list is inside the class function. I need to access the list from outside the class function.
Class A:
def insideclass(self):
values=[]
for i in range(10):
values.append(func())
def func():
if datetime.time.now()=="2021-06-25 10:15:52.889564":
values.clear()
return datetime.time.now()
classvariable=A()
classvariable.insideclass()
I don't want to use a global variable because I have different methods inside the class with the same variable name.
funcandsomecondition? Could you not add the condition and the call toclearto the class method?valuesas an argument to the function and perform theappendandclearin the function?funcseems like it would be cleaner? You wouldn't then have to callclearinfuncand could call it in the class method