簡體   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