I try to run command in my python file, which located in dynamic file. I try to use the import
statement, which as I understand is the better solution for this case.
Here is the code:
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()
The problem is that path is a string, and it gives me the following error:
import path as runcommand
ImportError: No module named path
How can I import the file, which I don't know its name, and run the main command from it?