我想通过命令行发送字典密钥。 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