1

I've found a way to run magic commands, eg

from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')

but how do you run something like !ls ?

Specifically, I need this to run a console script at runtime in Google Colab.

I have a library called dimcli that needs to create a local credentials file. Normally I'd invoke it like this !dimcli --init. However I'd like to run that command automatically each time the library gets loaded.

ntg
  • 12,950
  • 7
  • 74
  • 95
magicrebirth
  • 4,104
  • 2
  • 25
  • 22

1 Answers1

1

Think I got it

from IPython import get_ipython
get_ipython().run_line_magic("sx", "ls")

See https://github.com/ipython/ipython/blob/master/IPython/core/magics/osm.py#L668

magicrebirth
  • 4,104
  • 2
  • 25
  • 22