Description:
I am trying to return a value from a class when I call it.
I want the result of an object's method call upon creating the object.
I want to get the value of:
A().get_result()
# by just calling"
A()
My Question:
Why does A.get_result()
require the argument self
?
Minimal Reproducible Example:
Using the following class definition:
class A():
_arg_list = None
def __new__(self, my_args):
self._arg_list = my_args
return self.get_result()
def get_result(self):
return self._args_list[0]
Current Result:
A(['arg1','arg2'])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 A(['arg1','arg2'])
Cell In[5], line 9, in A.__new__(self, my_args)
5 def __new__(self, my_args):
7 self._arg_list = my_args
----> 9 return self.get_result()
TypeError: A.get_result() missing 1 required positional argument: 'self'
Desired Result:
A(['arg1','arg2'])
>> 'arg1'