I am calling a function (read_param) which depends on the 're' module, defined in a file (libfun.py) from a master script (master.py). When I do so I get a NameError:
NameError: global name 're' is not defined
I import the 're' module in the master script, but it seems that the function in the module I import can't use it. I'd prefer not to import 're' from within the function itself, since that seems wasteful. Why is this happening?
(this is a minimal example, not my actual code):
libfun.py:
def read_param(paramname, paramfile):
# code here depends on re module, e.g. calling re.split()
master.py:
#!/usr/bin/env python2
import re
import libfun as lf
lf.read_param('parameter', 'filename')