Most Pythonic way to provide global configuration variables in config.py? [closed]

How about just using the built-in types like this: config = { “mysql”: { “user”: “root”, “pass”: “secret”, “tables”: { “users”: “tb_users” } # etc } } You’d access the values as follows: config[“mysql”][“tables”][“users”] If you are willing to sacrifice the potential to compute expressions inside your config tree, you could use YAML and end … Read more

Python global variable scoping

Globals in Python are only global to their module. There are no names that you can modify that are global to the entire process. You can accomplish what you want with this: globals.py: value = 0 def default(): global value value = 1 main.py: import globals def main(): globals.default() print globals.value if __name__ == “__main__”: … Read more

Malloc function (dynamic memory allocation) resulting in an error when it is used globally

You can’t execute code outside of functions. The only thing you can do at global scope is declaring variables (and initialize them with compile-time constants). malloc is a function call, so that’s invalid outside a function. If you initialize a global pointer variable with malloc from your main (or any other function really), it will … Read more