Is there a simple method for calling shell command line arguments (like ls or pwd) from within python interpreter?
Asked
Active
Viewed 3,525 times
2 Answers
4
In plain python, you need to use something along the lines of this:
from subprocess import check_output
check_output("ls", shell=True)
In IPython, you can run either of those commands or a general shell command by starting off with !
. For example
! echo "Hello, world!" > /tmp/Hello.txt
If you're using python interactively, you would almost certainly be happier with IPython.

Mike
- 19,114
- 12
- 59
- 91
0
If you meant to use the Python shell interactively while being able to call commands (ls, pwd, ...) check out iPython.

Hai Vu
- 37,849
- 11
- 66
- 93