I should access the variable in a method in the class.
Because I did some data cutting in the method, I need the data of which data cutting is already done.
But I can access an instance variable that is only defined in the "__init__" method.
I give an example because of making clear my question. Let's see the below code.
class test:
def __init__(self,a,b):
self.a = a
self.b = b
def t(self,c,d):
self.c = c
self.d = d
FirstTest = test(3,4)
print(FirstTest.a)
SecondTest = test(3,4)
print(SecondTest.t(30,40).c)
I need "c" and "d", but I can not access of these. I only access to "a" and "b" If I try to access "c" and "d", below error is coming up.
---> 13 print(SecondTest.t(30,40).c)
AttributeError: 'NoneType' object has no attribute 'c'
Is there no code I can access the instance variable which is not defined in "__init__"?
tmethod doesn't return anything, so it's meaningless to try to access thecattribute of it. You need to do the method call as a separate statement from printing the attribute.class Test: ...,first_test = Test(3, 4), etc.