I have a module, that contains a bunch of functions that generate xml's
In other module I am constructing a class, and I want to assign one of those function to a class variable
Problem is, the fuction acts as a class method and when i call it from another class method, it passes self as a first argument.
Did i choose a good design approach? How to avoid passing self to a function? (@staticmethod decorator before generate = gen.generate doesn't work)
I would like to avoid making a class out of generate function if possible
Thanks!
generators.py
def generate(id, date):
pass
def generate_another():
pass
main.py
import generators as gen
class Client():
generate = gen.generate
def get_result(self, *args, **qwargs):
request = self.generate(id, date)
self.generate? Why not just call it directly asgen.generate(). Why should it be a static method instead of a function? This smells strongly of xyproblem.infogenerateor even an object methodgeneratethat uses state on the object andget_resultwould still work. Not saying that's the intent here, but its a reasonable pattern.client = Client(gen.generate). Then there's not even a need for the staticmethod decorator