def createSortDicDump(dic):
"""
Create a sorted ASCII representation of a dictionary. The order is sorted
according to the dictionary keys.
dic: Source dictionary (dictionary).
Returns: Sorted dictionary ASCII representation (string).
"""
if (type(dic) != types.DictType):
raise Exception, "Object given is not a dictionary"
keys = dic.keys()
keys.sort()
asciiDic = ""
for key in keys: asciiDic += ", '%s': '%s'" % (key, dic[key])
asciiDic = "{" + asciiDic[2:] + "}"
return asciiDic
评论列表
文章目录