我是 Python 新手。我正在嘗試將我的 shell 腳本轉換為 Python 語言。我在shell中有一段代碼如下,要轉換為Python。
我寫的外殼代碼:
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}]}";
}
這個函式有兩個引數,引數 1 是一個字串,它的值要么通過,要么失敗,第二個引數是索引號。
如果我收到第一個引數值作為“通過”,我構建一個陣列作為“v_pass_list”,如果我收到值作為“失敗”,我使用作為第二個引數接收的索引構建一個名稱為 v_fail_list 的陣列。
我在 Python 中也需要同樣的東西。
請幫助我。
非常感謝你。
問候, 馬查拉·拉梅什·庫馬爾
uj5u.com熱心網友回復:
對于“變數變數”(v_$1_list),您將使用將 映射$1到其他內容的 dict。
v_lists = {"pass": {}, "fail": {}}
def f_consolidate_output_test(flag, v_index, v_line):
v_lists[flag][v_index] = v_line
如果flagis not"pass"或,這將很高興崩潰"fail"。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/418626.html
標籤:
