Closest related question is this one: In Ipython, how can I pass arguments to a cell as though it were its own script?
I am writing an ipython notebook to make simulations and then create an animation in paraview. The way I do this is run a cell with the magic command
%%script pvpython
since paraview has its own interpreter. The problem is that I need it to pass it the directory of the vtu files as an argument (which are a variable in the IPython kernel). So far I have been unable to figure this out. I have tried:
%%script pvpython path/to/files
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo')
args = parser.parse_args()
print(args.foo)
But this gives an error: `Got unknown argument: path/to/files because the argument is being passed to the magic command not the python script. Is there a way to get around this?
Edit: This is different from the linked question because I am using a cell magic not line magic. I would prefer to have all my code visible in the notebook alone.