首页 新闻 会员 周边

求这段代码乱码的具体原因及解决办法

0
悬赏园豆:50 [已关闭问题] 关闭于 2018-03-23 17:47
复制代码
 1 class file_dir:
 2 
 3     def __init__(self,p='dir.txt'):
 4         import json
 5         self.path = p
 6         try:
 7             with open(p,'a') as f:
 8                 self.date = json.load(f)
 9         except Exception as e:
10             with open(p,'w') as f:
11                 json.dump({},f)
12                 self.date = {}
13     def setdir(self,*args):
14         for i in args:
15             b = '[%s]' % i
16             self.date.setdefault(b,{})
17             b = b+b
18         import json
19         with open(self.path,'w') as f:
20             json.dump(self.date,f)
21 
22 world = file_dir('world.txt')
23 world.setdir('亚洲','中国','陕西','西安','雁塔区','高新路')
复制代码

 文本结果如下:

{"[\u4e9a\u6d32]": {}, "[\u4e2d\u56fd]": {}, "[\u9655\u897f]": {}, "[\u897f\u5b89]": {}, "[\u96c1\u5854\u533a]": {}, "[\u9ad8\u65b0\u8def]": {}}

本人新手,写的代码乱码了。

不明白具体哪个步骤出的问题,请大神赐教。万分感谢

mengnan254的主页 mengnan254 | 菜鸟二级 | 园豆:202
提问于:2018-03-23 17:44
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册