I am using Python version : 2.6.6. I have a Python code test2.py inside directory : /home/admin.
And i am trying to run the file from inside : /home/admin/Practice/test.py.
My test.py code contains :
import os
filedir = os.path.realpath(__file__)
scriptdir = os.path.dirname(filedir)
print (filedir)
print (scriptdir)
newfile = scriptdir + "/../" + "test2.py"
new_module = __import__(newfile)
exec("python new_module 100 10"
Now i know this is probably not the right way to run a Python script from another. But when i run this i get :
[admin@centos1 Practice]$ python test.py
/home/admin/Practice/test.py
/home/admin/Practice
Traceback (most recent call last):
File "test.py", line 7, in <module>
new_module = __import__(newfile)
ImportError: Import by filename is not supported.
We have to run the Python script : /home/admin/test2.py which is inside the variable : newfile inside test.py.
Can someone please guide me as to how this should be done?
Thanks for the learning.