Search code examples
pythonxdgutils

Python open file in specific application using xdg-utils?


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.


Solution

  • 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"