marylandgis

Import module - undefined global variable

Discussion created by marylandgis on Jun 4, 2012
Latest reply on Jun 6, 2012 by marylandgis
I thought I understood and fixed this problem:  A variable defined in a module remains undefined after I import the module.  Here is the simplified version.

The main script and the module are in the same folder/dir.

This is my module:  mysettings.py

def main():

    myvar = "This is imported."

if __name__ == '__main__':
    main()



This is my script:  irp.py:


import mysettings

def main():

    print myvar

if __name__ == '__main__':
    main()



Interpreter error:

NameError: global name 'myvar' is not defined

Can you tell me why?

Thanks,

Outcomes