Python Universal Variables

Python modules as data containers are very handy to store “universal variables” spread around in your code base.

If you make a py file with variables (

xToolVer = 3.2
yToolVer = 1.2
emergency = 0

When you import uVars you can use the variables like this:

import uVars
if not uVars.emergency:
    if uVars.xToolVer > currentVersion: updateStuff

This is very handy for things like versions. It is also very handy to keep an emergency switch and institute anywhere in code, where a kill switch might come in handy. Another use I’ve found is for certain paths that can be used in situations before tools are aware of their environment (catch 22 situations). “Gotta have this path to build my environment”. The file could also contain paths that you want to sys.path.append directly if those paths are the same for everyone. If they are not, they can contain relative paths and you let other data fill in the root path.

/Christian Akesson

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *