I have 2 python files. One is trying to import the second. My problem is that the second is called math.py. I can not rename it. When I try to call a function inside math.py, I cannot, because the result is a global math module. How do I import a local file instead of a global one. I am using Python 2.7 and this is (approximately) my import status:
cstr = "math" command = __import__(cstr)
Later I will try:
command.in_math_py_not_global()
Edit: a more complete example:
def parse(self,string): clist = string.split(" ") cstr= clist[0] args = clist[1:len(clist)] rvals = [] try: command = __import__(cstr) try: rvals.extend(command.main(args)) except: print sys.exc_info() except ImportError: print "Command not valid"
source share