Imagine I have an initializer with optional parameter
def __init__(self, seed = ...):
Now if parameter is not specified I want to provide a default value. But the seed is hard to calculate, so I have a class method that suggests the seed based on some class variables
MyClass.seedFrom(...)
Now how can I call it from that place? If I use self
:
def __init__(self, seed = self.__class__.seedFrom(255)):
I definitely don't know what is self at that point. If I use the class name directly (which I hate to do):
def __init__(self, seed = MyClass.seedFrom(255)):
it complains that
name 'MyClass' is not defined
I'm also interested to learn the pythonic way of doing this. And I hope that pythonic way is not hardcoding stuff and making it nil by default and checking it later…