繁体   English   中英

带有括号的Python字典打印

[英]Python dictionary print with parentheses

我正在尝试编辑此函数,以便该词典的值不会被打印在括号中并且将是可迭代的:

def traverse_appended(key):
reg_dict = {}
#keypath = r"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
for item in traverse_reg(key):
    keypath_str = str(keypath+item)
    reg_dict[item] = str(get_reg("Displayversion", keypath_str)), str(get_reg("DisplayName", keypath_str))
    #reg_dict[item] = get_reg("DisplayName", keypath_str)

return reg_dict

预期的输出是:

{'DXM_Runtime': 'None', 'None'}

函数输出:

{'DXM_Runtime': ('None', 'None')}
#Consider traverse_appended returns following dict.
#I think, converting func_dict values which are tuple into string, will help you to get expected  output.

func_dict = {"DXM_Runtime":('None','None'),
             "TMP_KEY":('A','B')
             }

derived_dict = {}
for k,v in func_dict.viewitems():
    tmp_str = ",".join(v)
    derived_dict[k] = tmp_str

print derived_dict

#Output

E:\tmp_python>python tmp.py

{'DXM_Runtime': 'None,None', 'TMP_KEY': 'A,B'}

#If this doesn't help you, then please post the code for get_reg and traverse_reg function also.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM