-3

Is there a simple method for calling shell command line arguments (like ls or pwd) from within python interpreter?

P0LYmath
  • 23
  • 1
  • 7

2 Answers2

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
  • 17,346
  • 10
  • 55
  • 86
0

If you meant to use the Python shell interactively while being able to call commands (ls, pwd, ...) check out iPython.

Hai Vu
  • 34,189
  • 11
  • 57
  • 87