I am very new to Python and OOP in general. I have a very easy question thou that just won't be working for me. I have a class with several functions.
class Test:
def a(self):
var1 = 1
return var1
def b(self):
var2 = 2
return var2
def c(self):
var3 = a()
var4 = b()
Why will this just tell me that it does not know a() or b() I guess I am missing some important basic knowledge. Thanks
The Actual I am refering to:
class Token:
# get new token
def post_new_token(self):
payload = "***"
headers = {
'authorization': "***",
'content-type': "application/x-www-form-urlencoded"
}
r = requests.post(settings.GET_NEW_TOKEN, data=payload, headers=headers)
r_json_obj = r.json()
# print ("I am from post_new_token:")
# print r_json_obj
return r_json_obj
# use the new token
def get_config(self):
# here I want to use the returned value:
access_token = self.post_new_token()
headers = {
'authorization': "Bearer " + str(access_token),
'cache-control': "max_age 3600"
}
r = requests.get(settings.GET_CONFIG, headers=headers)
# print ("I am from get_config:")
# print access_token
return r
So if use the prints it actually goes fine but when it gets to self.post_new_token() it runs all this function again.
There is no error coming but if I use the prints to see whats happening I get it like this:
I am from post_new_token:
{***}
I am from get_config:
{***}
I am from post_new_token:
{***}
Why is it printing
I am from post_new_token:
{***}
again?
self.a()and similarly forb. To know why, I suggest reading the tutorial section on classes. It would be well worth your time to read it over carefully and see where your misunderstand lies.selfwhen calling your instance methods. Update your question with what is actually going on and add the full stack trace you are receiving, if any.