Ron*_*th 3 python jupyter-notebook
我正在尝试从 jupyter notebook 运行一个名为“Volatility_Spreadsheet_Prepare.py”的程序,同时将多个文件作为参数传递给程序。我的代码如下:
for filename in all_csv_files:
%run 'Volatility_Spreadsheet_Prepare.py' filename
Run Code Online (Sandbox Code Playgroud)
此处all_csv_files包含当前目录中所有 CSV 文件的列表。该程序将文件名作为参数。
在这里,jupyter notebook 将文件名视为字符串,而我希望它考虑存储在 for 循环的变量“文件名”中的名称。我该怎么做呢?
Jupyter Notebook 使用 $name、bash 样式扩展变量。
尝试这样的事情(注意文件名前面的“$”):
for filename in all_csv_files:
%run 'Volatility_Spreadsheet_Prepare.py' $filename
Run Code Online (Sandbox Code Playgroud)
请参阅此处了解更多信息