Answer the question
In order to leave comments, you need to log in
Is it bad to use one global constant?
Hello.
I am writing a program in which I have a login and password for each user + access rights.
Here is my question. I need to store the user's access rights throughout the program.
Access rights are used in different function classes and program files.
It seems to me that the simplest solution is to create one global constant in which access rights will be stored.
But I heard that global variables are evil. But do not pass a variable from class to class that will say "admin" or "work".
Tell me what do you think about this?
Answer the question
In order to leave comments, you need to log in
Use a construct like:
class Auth:
_instance = None;
def __init__(self, user, pswd):
# some initialization
self._id = None
pass
def getId(self):
return self._id
@staticmethod
def getInstance(user, pswd):
if Auth._instance is None:
Auth._instance = Auth(user, pswd)
return Auth._instance
# later use authorization as Auth.getInstance().getId();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question