-1

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.

Good Person
  • 1,437
  • 2
  • 23
  • 42
Crevitus
  • 112
  • 2
  • 11
  • 1
    Generally, if you've got circular dependencies in your modules, you're doing something wrong and should consider refactoring to break the circle. – dano May 20 '14 at 20:38
  • xdg-utils is not linux specific: it runs on any xdg-compliant system – Good Person May 20 '14 at 21:01
  • I agree, but sadly the hand in for my project is a couple of days away and so i dont have time to rework it. This was my first python project and so i would want to rewrite most it. So badly written but oh well! – Crevitus May 20 '14 at 21:09

1 Answers1

2

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"

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125