【问题标题】:How to run a python project multiple time on different configurations?如何在不同配置下多次运行 python 项目?
【发布时间】:2023-02-02 00:14:24
【问题描述】:

我有一个 python 项目,它将一个 .csv 文件和一些参数作为输入,然后返回一些结果。 每次我想尝试我的代码的新编码功能并获得结果时,我都必须运行更改 .csv 名称和其他参数的程序。所以每次这个参数都需要很长时间才能改变,因为我有很多不同的输入文件。

有一种用 python 编写程序的方法可以为我做这个吗? 例如一个程序:

- run "project.py" n times
- first time with "aaa.csv" file as input and parm1=7, then put results in "a_res.csv"
- second time with "bbb.csv" file as input and parm1=4, then put results in "b_res.csv"
- third time with "ccc.csv" file as input and parm1=2, then put results in "c_res.csv"
- fourth time with "ddd.csv" file as input and parm1=6, then put results in "d_res.csv"
- ...

谢谢!

【问题讨论】:

  • 通常,您只需编写一个快速的 shell 脚本来使用不同的参数执行您的 Python 脚本。

标签: python


【解决方案1】:

是的,列出你想要的配置,并在循环中执行你的函数,循环遍历这些配置

configurations = [
    ["aaa.csv", 7, "a_res.csv"],
    ["bbb.csv", 4, "b_res.csv"],
    ["ccc.csv", 2, "c_res.csv"],
    ["ddd.csv", 6, "d_res.csv"]]

for c in configurations:
   # assuming your python function accepts 3 parameters:
   # input_file, param1, output_file

   your_python_function(c[0], c[1], c[2])

【讨论】:

    猜你喜欢
    • 2013-02-18
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多