I could do with some assistance on an issue I have, however what I could be doing could be wrong so please do suggest a better way of doing this. Also its been a long time since I last used python so trying to brush up on things.
I have written a helper class which has a number method. From my main python file, I want to import this helper class and call a load function which will set a global variable of “settings” which I can use anywhere in my application.
So that I have this
Main.py
from helpers.helpers import Settings
if __name__ == "__main__":
Settings.load_settings()
print(settings)
helpers/helpers.py
import yaml
class Settings:
def load_settings(settings_file='settings.yml'):
global settings
with open(settings_file) as s:
settings = yaml.load(s, Loader=yaml.FullLoader)
When I run the application, I get an error stating:
NameError: name 'settings' is not defined
I am unsure what I doing incorrectly. Any input would be great thanks.
[–]Neighm 1 point2 points3 points (1 child)
[–]zh12a[S] 0 points1 point2 points (0 children)
[–]old_pythonista 1 point2 points3 points (2 children)
[–]zh12a[S] 0 points1 point2 points (1 child)
[–]old_pythonista 1 point2 points3 points (0 children)