0

I already have

import os
exec(os.popen("Packman Game.py").read()

But it doesn't do anything and doesn't give me an error message What do I need to do?

PS:Without typing into the shell.

kindall
  • 158,047
  • 31
  • 244
  • 289

2 Answers2

0

You can use os.system.

For example :

import os
os.system("myOtherPythonScript.py [parameters]")
Xavier V.
  • 5,160
  • 5
  • 25
  • 34
  • 2
    This is probably ok for this specific case, but generally it isn't recommended, because it forces you do use a shell to execute the command. This can be dangerous if you're accepting user input and using it as part of the command. Instead, the [`subprocess`](https://docs.python.org/2/library/subprocess.html) module is preferred. – dano Jul 29 '14 at 19:42
0

Or you can also use subprocess:

    <!-- language: python -->
    import subprocess
    result = subprocess.check_output("Packman Game.py",shell=True) 

If you want to read the result.

Luna Feng
  • 307
  • 1
  • 5