问题描述
我试图从jupyter笔记本中运行一个名为“ Volatility_Spreadsheet_Prepare.py”的程序,同时将多个文件作为参数传递给该程序。 我的代码如下:
for filename in all_csv_files:
%run 'Volatility_Spreadsheet_Prepare.py' filename
在这里, all_csv_files
包含当前目录中所有CSV文件的列表。
该程序将文件名作为参数。
在这里,Jupyter Notebook将文件名视为字符串,而我希望它考虑存储在for循环的变量“文件名”中的名称。 我该怎么做呢?
1楼
Jupyter Notebook使用bash样式的$ name扩展变量。
尝试这样的事情(注意文件名的“ $”开头):
for filename in all_csv_files:
%run 'Volatility_Spreadsheet_Prepare.py' $filename
看到更多信息
2楼
输入这个
!python Volatility_Spreadsheet_Prepare.py all_csv_files