我尝试在python文件中运行命令,该文件位于动态文件中。我尝试使用import
语句,据我所知,这是本例的更好的解决方案。在
代码如下:
from subprocess import call
import tarfile
from contextlib import closing
def tarfile1(path):
with closing(tarfile.open(path)) as tar:
tar.extractall(path)
import path as runcommand
runcommand.main()
问题是path是一个字符串,它给出了以下错误:
^{pr2}$如何导入不知道其名称的文件并从中运行主命令?在
您必须使用^{} 。在
注意:请确保模块的父目录在PYTHONPATH中或添加到
sys.path
中。在使用
取而代之的是
相关问题 更多 >
编程相关推荐