Inside my class I have:
def refresh(self, func = None, *args):
if not func:
return
new_data = func(*args)
self.set_text(new_data)
But I have 2 problems:
What if
funcdoesn't take any parameters? Why can't I do*args = None? like I want to do something like this:def refresh(self, func = None, *args = None): if not func: return if *args: new_data = func(*args) else: new_data = func() # func doesn't take any parameters self.set_text(new_data)When I try to run my code before the edits I get:
TypeError: function takes 0 positional arguments but 1 were given
Why is that?
Here is my main:
def hello_world():
return 'hello'
tmp2 = LLabel('Hi There!')
tmp2.refresh(hello_world, None)