Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a python program from jupyter notebook while passing filenames as arguments

I am trying to run a program named "Volatility_Spreadsheet_Prepare.py" from jupyter notebook while passing multiple files as arguments to the program. My code is as follows:

for filename in all_csv_files:
    %run 'Volatility_Spreadsheet_Prepare.py' filename

Here, all_csv_files contains a list of all the CSV files in the current directory. This program takes filename as an argument.

Here, jupyter notebook considers filename as a string while I want it to consider the name stored in the variable 'filename' of the for loop. How do I do this?

like image 570
Ronith Avatar asked Nov 22 '25 12:11

Ronith


1 Answers

Jupyter Notebook expands variables with $name, bash-style.

Try something like this (note the '$' infront of filename):

for filename in all_csv_files:
    %run 'Volatility_Spreadsheet_Prepare.py' $filename

See here for more information

like image 65
gehbiszumeis Avatar answered Nov 25 '25 00:11

gehbiszumeis