3

For example, I have a Python module and a iPython module,

cmd.py

import sys
print sys.argv

test.ipynb

for i in range(5):
   %run cmd.py i

When I run test.ipynb, it just print ['cmd.py', 'i'] multiple times. How can I pass the value of i instead of 'i' as a command line argument?

1
  • have you tried %run cmd.py $i ? Commented Jan 6, 2017 at 14:44

1 Answer 1

6

the shell mode interprets everything literally (else cmd.py would be evaluated as well). I would just do:

for i in range(5):
   %run cmd.py $i

from http://ipython.readthedocs.io/en/stable/interactive/reference.html

IPython also allows you to expand the value of python variables when making system calls. Wrap variables or expressions in {braces}:

For simple cases, you can alternatively prepend $ to a variable name

Sign up to request clarification or add additional context in comments.

1 Comment

I must admin I spent at least 15 minutes in the documentation to find the information. Wasn't the most accessible piece of information :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.