1
os.system(sys.executable+" "+sys.prefix+"/bin/"+arg)

This is part of the pip console app that comes with qpython for android

Ricky Wilson
  • 3,187
  • 4
  • 24
  • 29

2 Answers2

3

A better way might be to use subprocess.run and os.path.join:

from subprocess import run
from os.path import join
from sys import executable, prefix
run([executable, join(prefix, 'bin', arg)])

The interface is much cleaner and more robust. It also offers much more control over how the process is called.

Notice that you can use a list for the arguments instead of artificially concatenating them. This makes life much easier if the path contains a space.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
-2

I think this is more pythonic but still needs something.

def modcmd(arg):
    exe = sys.executable + ' '
    prefix = sys.prefix + '/bin/'
    cmd = exe + prefix + arg
    os.system('clear')
    os.system(cmd)
Ricky Wilson
  • 3,187
  • 4
  • 24
  • 29