I have a code module.py that is imported into my main.py so I can use its functions, which are defined with def. The imported module only has def functions.
There are some if statements in the functions that I'd wish to manipulate automatically from main.py.
Like for example
main.py
import module as md
BoolIfState=True
for i in range(10):
md.runfunction(i)
module.py
def runfuntion(i):
if BoolIfState:
print i
else:
print i-10
return None
Here the definition of BoolIfState in main.py changes how runfunction from module behaves. I tried adding global BoolIfState inside the function but it didn't change the behavior.
Obviously, the actual codes are much more difficult but it's the same basic idea.
Is there a way to do this?
Edit: I am avoiding giving the variable as an input to the function because then it will become cluttered given all the variables that would need to be added. I need to the same thing to approximately 5 variables, and with it, the cleanliness of having functions defined inside the module are lost.