Python字典打印括号

时间:2015-08-24 04:17:01

标签: python dictionary

我正在尝试编辑此函数,因此字典的值不会打印在括号中并且可以迭代:

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')}

1 个答案:

答案 0 :(得分:0)

#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.