擅长:python、mysql、java
<p>我不确定这是不是做你想做的最好的方法。我创建了一个类来表示您想要的数据。但是,您应该注意到不再返回字典数据类型。这只是表示数据的一种快速方法。第一行<code># -*- coding: utf-8 -*-</code>全局指定编码类型。所以,如果你只想打印你的字典,这是可行的。在</p>
<pre><code># -*- coding: utf-8 -*-
class print_dict(object):
def __init__(self, dictionary):
self.mydict = dictionary
def __str__(self):
represented_dict = []
for k, v in self.mydict.items():
represented_dict.append("{0}: {1}".format(k, v))
return "{" + ", ".join(represented_dict) + "}"
dic = {1: 'Ááa', 2: 'lol'}
print print_dict(dic)
</code></pre>