python - 实验设置中的自动化脚本

标签 python

大家下午好,

我是一个Python初学者,我正在尝试实现以下脚本来生成自动输入机器的命令列表。脚本现在看起来像:

print("re 1")
make_same = "xfb nc_proc 0"
first_exp = 1
exp_id = str(first_exp)
copy_par = "rpar re999"
next_please = "re " + exp_id


def macro_maker():
     parameters = [copy_par, make_same, next_please]
     for settings in parameters:
           print(settings)

macro_maker()

def repeat(f, n):
    for i in range(n):
        f()
repeat(macro_maker, 1)

我想对其进行修改,使其无需我的输入即可自动传递到下一个实验。例如,当前输出为:

re 1
rpar re999
xfb nc_proc 0
re 1
rpar re999
xfb nc_proc 0
re 1

虽然我想要以下输出:

re 1
rpar re999
xfb nc_proc 0
re 2
rpar re999
xfb nc_proc 0
re 3

我尝试了好几天查找类似的问题,但每次都只能提出新的错误!

非常感谢任何可以帮助我完成这项任务的人。

最佳答案

问题仅在于您的 next_please 字符串在整个脚本中保持不变。因此它总是打印相同的内容're 1'

据我了解,这是唯一要更改的参数,您可以做的是:

make_same = "xfb nc_proc 0"
copy_par = "rpar re999"
next_please = "re {}"


def macro_maker(index):
     print(next_please.format(index))
     parameters = [copy_par, make_same]
     for settings in parameters:
           print(settings)

def repeat(f, n):
    for i in range(1, n+1):
        f(i)

repeat(macro_maker, 2)

macro_maker 采用实验索引,并以不同于所有其他参数的方式对待 next_please,向其提供当前索引以格式化模板字符串"re {}".

关于python - 实验设置中的自动化脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138036/

相关文章:

python - 更改副本,但更改父级。为什么?

python - PAM Python Unix 身份验证,无需 root 权限

python - 在 Post 请求正文中发送列表值以验证 Pydantic 模型

python - 柯里化(Currying) UDF - Pyspark

python - 对列进行条件计数并对结果进行平均计算

python - 如何在一个张量板选项卡中显示多个图像,就像在 tf-object-detection-api 中完成的那样

python - Healpy map2alm 和 alm2map 不一致?

python - 从 S3 读取 KMS 加密文件

python - 当玩家在 5x5 网格上画出 2x2 网格时,如何让游戏停止

python - 如何使用生物服务在不指定生物体的情况下访问 KEGG 条目?