So I'm making a program and I have made a module to go along with it. In the module I have a function where I use exec() to create a global variable:
def FunctionName(headings):
for c in headings:
exec('global %s' % c)
<Other code...>
And I have another script:
import modulename
headings = ['test1','test2','test3']
modulename.FunctionName(headings)
print(dir(modulename))
print(modulename.test1)
But this returns
['FunctionName',<Other function but no variables>]
Traceback (most recent call last):
File "<path>\main_program.py", line 6,
in <module>
print(modulename.test1)
AttributeError: module 'modulename' has no attribute 'nice'
If I manually say
global <Var name>
in the module, it works fine. Any ideas why and how to fix?