![](/img/trans.png)
[英]How do I export environment variables using a script in the same shell in python?
[英]How do I write the same shell script in Python?
我是 Python 的新手。 我正在尝试将我的 shell 脚本转换为 Python 语言。 我在shell中有一段代码如下,要转换为Python。
我写的 Shell 代码:
f_consolidate_output_test()
{
v_index=$2
eval "v_$1_list[${v_index}]"=${v_line}
#echo "Pass list[${v_index}] : ${v_pass_list[${v_index}]}";
#echo "Fail list[${v_index}] : ${v_fail_list[${v_index}]}";
}
这个 function 有两个 arguments 参数 1 是一个字符串,它的值是通过或失败,第二个参数是索引号。
如果我收到第一个参数值作为“通过”,我构建一个数组作为“v_pass_list”,如果我收到值作为“失败”,我使用作为第二个参数接收的索引构建一个名称为 v_fail_list 的数组。
我在 Python 中也需要同样的东西。
请帮助我。
非常感谢你。
问候, 马查拉·拉梅什·库马尔
对于“变量变量”( v_$1_list
),您将使用将$1
映射到其他内容的字典。
v_lists = {"pass": {}, "fail": {}}
def f_consolidate_output_test(flag, v_index, v_line):
v_lists[flag][v_index] = v_line
如果flag
不是"pass"
或"fail"
,这将很高兴地崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.