我正在尝试从用户那里获取文件名,然后execfile()
用来执行文件。下面是我的代码:
print "Please enter the name of the file"
filename = raw_input().split(".")[0]
module = __import__(filename)
execfile(module) <-- this is where I want to execute the file
我了解它的execfile()
工作原理如下:
execfile("example.py")
当文件名作为变量传递时,我不确定如何执行此操作。我正在使用python 2.7。