I think.
If you want a reference to yourself, in the module
import sys
self = sys.modules[__name__]
It is convenient to write such as. If you are using python3 series
import importlib
self = importlib.import_module(__name__)
But it's okay.
The reason why I suddenly wanted to say this is because I was looking at the code I wrote a long time ago and thought that it was really black history. All you have to do is define the create function in a module called hogefactory.py.
somemodule.py
class HogeFactory:
@staticmethod
def create(params):
"""A method that creates and returns a Hoge object"""
#Various complicated processing
# ...
return Hoge(some_args, some_kwargs)
As an aside, when should I use the static method of python? I don't remember writing recently.
Recommended Posts