Python open file in specific application using xdg-utils?

710 views Asked by At

i have this line of code in my python script:

            os.system("xdg-open " + "User_interaction.py")

It works fine and opens the python file in the default application associated with the .py file type but i want it to run the file. I know i could usually just import the module but the user_interaction file is already importing the file that is code is written in so they cannot import each other.

How do i get the python script to execute the user_interaction script?

Cheers.

1

There are 1 answers

0
Haifeng Zhang On BEST ANSWER

You can have this os.system('python file.py') in your file

test.py

import os
os.system('python hello.py')

hello.py

print "hello world"

run python test.py, it will print out "hello world"