Skip to content Skip to sidebar Skip to footer

Run IPython In A Script

I am trying to do some scripting with IPython, but I am finding that it behaves very differently in a script to when I run an interactive shell. For example, I can run the followin

Solution 1:

They are working due to IPython magic but they are shell commands and do not work in Python. To get them consider the subprocess library. Where you would have spaces in a shell command instead have comma-separated values in the list.

import subprocess
subprocess.check_call(['ls'])
subprocess.check_call(['ls', '-a'])

Post a Comment for "Run IPython In A Script"