3 ms·
You can kinda sorta make private variables in Python with some namespace abuse: def make_get_private(var): . . . .private_var = var . . . .def get_private():
by willcipriano 6y ago
You can kinda sorta make private variables in Python with some namespace abuse:
def make_get_private(var):
. . . .private_var = var
. . . .def get_private():
. . . . . . . .return
private_var
. . . .return get_private
get_private = make_get_private("spam")
You can't readily modify private_var after it is set in this case, you could also make and return a set_private function as well. I imagine you could do a whole module like this and then have it create it's functions at runtime to produce this "private" namespace. It would be a mess though.