I have two files module.py
and main.py
In module.py
I have a function which uses a constant defined outside of its scope.
#module.py
def add(x):
s = x + const
return s
if __name__ == '__main__':
const = 2
print(add(2))
It prints 4
as output when run directly.
In main.py
I have:
#main.py
import module as m
const = 2
print(m.add(2))
It gives error: NameError: name 'const' is not defined
Is there a way to make m.add() look for const
in main.py
global scope? I'd like not to pass const
to add()
as a function variable.