Accessing globals from within import

Viewed 9

Is there anyway to access globals from within an imported module. I splitted my code for easy of coding in two files but it seems I can't access globals anymore from within a function in the import.

Main file snippets :

from funcmap import FuncMapper
mapper = FuncMapper()

from mappings import *
arrays = {}

...

arrays['t'] = sa.attach("shm://"+splitted3[1])
rows, cols = arrays['t'].shape
arrays['s'] = sa.create("shm://"+scratchpad+".ARR", (rows,20), np.float64)

mappings.py file :

@mapper.map(r'Somemapping!(?P<first>.*)')
def my_func(first):
    global arrays
    print (str(arrays['t']), file=open('/tmp/'+logfilename+'.log', 'a+'))
    print (str(arrays['s']), file=open('/tmp/'+logfilename+'.log', 'a+'))

which throws NameError("name 'arrays' is not defined")

0 Answers
Related