I'm new to this website, may I have some help on the following?
I have a main.py
program that contains the dictionary loaddict
.
I have a module outside of the main program that contains multiple functions which all of them requires the dictionary loaddict
from the main program.
Is there a way to access the dictionary loaddict
from multiple functions in this module without setting loaddict
as a parameter for all of them?
The following code doesn't work, as the remaining function still does not have access to loaddict
from the function dgm
even with the use of keyword global
.
## main program (main.py)
## user inputs data into dictionary: loaddict = {some data}
import BeamDiagram.dgm(loaddict, other parameters)
## module (BeamDiagram.py)
def dgm(loaddict, other parameters):
global loaddict
## some calculations, this part is fine
def function1(some parameters):
## calculations that requires loaddict
def function2(some parameters):
## calculations that requires loaddict
def function3(some parameters):
## calculations that requires loaddict