1

I'm trying to run an external python file from a Jupyter notebook. The external python file takes a file path as an argument. I'd like to know how to pass this file path to the external .py file being run, from a string variable in the Jupyter notebook.

The following is what I've tried, and the error message which is returned:

path = '/Users/documents/'
%run script.py path

Which returns:

IndexError: list index out of range

However I get the expected results if I run:

%run script.py /Users/documents/

I'd like to be able to store the string as a variable for ease of use (not having to edit the file path in multiple parts of a notebook. Is there an easy solution?

Ian Gullett
  • 107
  • 9
  • Does this answer your question? [Running a Jupyter notebook from another notebook with parameters](https://stackoverflow.com/questions/58880620/running-a-jupyter-notebook-from-another-notebook-with-parameters) – CryptoFool Nov 18 '20 at 23:02

1 Answers1

0

You should put your variable inside { }. Something like this:

%run script.py {path}

I searched few hours until I found it here

Mehdi
  • 999
  • 13
  • 11