I am building a class that has a number of methods to request different data from the same website. The catch is the session_id needs to stay persistent across all instance methods.
I have written some mock code below and was wondering if this is the correct way to go about it or have I got it all wrong?
import random
class classTest():
def __init__(self):
self.session_id = None
def set_session_id(self):
if self.session_id == None:
self.session_id = random.randrange(0,1000)
return self.session_id
def use_session_id(self):
return self.set_session_id()
def use_session_id_again(self):
return self.set_session_id()
In the above example I mocked the session_id with a random number and when I test the two different methods I get persistent results, which means it is working great... but is this the correct way to achieve this? Can anyone advise on a better / proper way to do this?