I have a class with two instance attributes. For example:
class Test():
def __init__(self, parameter):
self.one = self.somefunction(parameter)
self.two = 'somestring'
In the same class I define a function somefunction which will, accordingly to the above coding, be called at the time the object is created. While I tried this, I could set self.one when I return some value inside my somefunction(parameter), like:
def somefunction(parameter):
return ...
However, this doesn't feel like best practice.What's the best way to set an initial value of an instance dynamically?
__init__rather thaninit, ie a constructor for theTestclass.)