Jupyter magic commands (starting with a single %
, e.g. %timeit
) can be run in a script using the answer from How to run an IPython magic from a script (or timing a Python script)
However, I cannot find an answer on how to run cell magic commands, e.g. In Jupyter we can do:
%%sh -s $task_name
#!/bin/bash
task_name=$1
echo This is a script running task [$task_name] that is executed from python
echo Many more bash commands here...................
How can this be written such that it can be executed from a python script?