How do I execute a program or call a system command?


import subprocess["ls", "-l"]) 

Another common way is os.system but you shouldn’t use it because it is unsafe if any parts of the command come from outside your program or can contain spaces or other special characters, also is generally more flexible (you can get the stdoutstderr, the “real” status code, better error handling, etc.). Even the documentation for os.system recommends using subprocess instead.

On Python 3.4 and earlier, use instead of .run:["ls", "-l"])