I'm creating an application that uses a base class to hold all of the configuration values, import methods, etc.
/
- application.py
+ class foo
+ config = None
+ def loadconfig
- otherfile.py
+ class bar
+ def getconfigvalue
So, if I start application.py and it runs loadconfig, which loads a value into foo.config, and then imports (inside said function - to get around circular imports) otherfile.py and creates a new bar object, which then tries to get a configuration value from foo.config, but says that foo.config is equal to None. Any suggestions?
Simplified code:
main.py
class Main:
config = None
@staticmethod
def start():
## Load the configuration from a file, creating a dict in Main.config ##
Main.other()
@staticmethod
def other():
from otherfile import otherclass
otherclass()
Main.start()
otherfile.py
from main import Main
class otherclass:
def __init__(self):
print(Main.config) ## Prints "None"
Note: It was arranged like this because that's how it actually works in the program; I feel like it has something to do with scope
Full source files:
asgard.py: http://pastebin.com/jRkWzrPq
library/childcontainer.py: http://pastebin.com/6a561Nun
loadconfigis a static method, and when setting config, I usefoo.config = "config"and try to access it asapplication.foo.config## Load the configuration from a file, creating a dict in Main.config ##line represents loading it. It's loaded from a YAML file, and I honestly didn't feel like typing it out.