Super-global variables in Python exploiting the builtins package
I just saw a lovely idea in Python to create super-global variables.
That is variable that will be available somehow globally in all the packages.
It was done by creating attributes on the builtins module Like this:
examples/python/super_global.py
import builtins builtins.answer = 42
Then you can use them like this:
examples/python/use_super_global.py
import builtins import super_global print(builtins.answer)
This is a very bad idea. It makes the code very hard to maintain.
In many cases you might be better off using a module or caching for solving whatever issues you encounter.
Published on 2021-08-30