I have 2 files that run together, a ui file and a util file.
This is the UI file:
import util
class MainWindow(object):
...
def method_context_callback(self, *args):
if args[0] == 'M1':
self.ctx = utils.M1Context(...)
self.ctx.run_context()
elif args[1] == 'M2':
self.ctx = utils.M2Context(...)
self.ctx.run_context()
This is the Util file:
class M1Context(object):
def __init__(self):
...
def run_context(self):
# Do something when Method01 is used
class M2Context(object):
def __init__(self):
...
def run_context(self):
# Do something when Method02 is used
Is there a need to make run_context
methods in the utils.py
as a staticmethod? In my UI, there are 2 buttons, one each for Method01 and Method02, where User can use the buttons anytime he/she liked while the UI is being active.
I asked this because while I was reading something online, it was mentioned that it can be considered. To be honest, I am not very familiar with @staticmethod
as generally I wrote my code in this format.
How do I know when and in what sort of situations should I make it as a static method?