【发布时间】:2014-03-04 19:20:50
【问题描述】:
我正在尝试通过命令行发送字典键。 sys.argv[1] 有钥匙。
此密钥存储在var2 中并发送到append_func,这是另一个附加文件。
每当我为键提供命令行参数时动态地,我希望字典被附加。但是每次我输入新的命令行参数时它都会覆盖
请看代码:
##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 test dictionary.py test1 我想得到输出{test : hello, test1 : hello}
标签: python dictionary