我想通過命令行發送字典密鑰。 sys.argv[1]
有關鍵。 此密鑰存儲在var2
併發送到append_func
這是另一個文件附加。 動態每當我給密鑰的命令行參數,我想字典被附加。但其覆蓋每次當過我進入新的命令行參數在Python中更新一個字典與另一個字典
請看代碼:
##filename : dictionary.py##
import sys
import append
dic={}
var1=sys.argv[0]
var2=sys.argv[1]
dicto=append.append_fun(var2,dic)
dic=dic.update(dicto)
print dic
##filename : append.py##
def append_fun(var2,dic1):
dic1[var2] = "hello"
return dic1
在命令行中我打電話dictionary.py test
。再次當我打電話時,dictionary.py test1
它不會附加dic
這兩個值,它會覆蓋第二個。
請幫助我如何追加dic
字典
您期待什麼輸出?每次我 –
我運行dictionary.py文件,如下所示: dictionary.py測試 dictionary.py test1的 我想輸出{你好測試:你好,TEST1}用不同的字符串運行dictionary.py。 例如:dictionary.py test1 dictionary.py test 輸出結果應該是:{test1:hello,test:hello} – user3378508