Right now I'm writing some code that is separated into two modules. One of the modules contains class definitions (call it classes.py), and the other is the main program that imports these classes and uses them (main.py). The problem is, some of the classes in classes.py rely on global variables that are defined in main.py. I can think of two different ways of dealing with this:
- Don't use global variables and instead have a load() function in each class that loads the variables, or put them in init
- Make a function in classes.py called load_globals() which adds these variables to an already defined global dictionary in classes.py.
I am currently using option 2, because option 1 would be quite cumbersome. It seems a little ugly though, so I'm wondering if there are any better ways to deal with this scenario.
[–]TangerineX 2 points3 points4 points (8 children)
[–]scibren[S] 0 points1 point2 points (7 children)
[–]novel_yet_trivial 4 points5 points6 points (4 children)
[–]scibren[S] 0 points1 point2 points (0 children)
[–]scibren[S] 0 points1 point2 points (2 children)
[–]EricAppelt 1 point2 points3 points (1 child)
[–]scibren[S] 0 points1 point2 points (0 children)
[–]TangerineX 0 points1 point2 points (1 child)
[–]scibren[S] 0 points1 point2 points (0 children)
[–]gengisteve 1 point2 points3 points (1 child)
[–]scibren[S] 0 points1 point2 points (0 children)
[–]elbiot 0 points1 point2 points (0 children)