!/usr/bin/env python
-- coding: utf-8 --
import json
import pprint
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def readfile(f):
with open(f, 'r') as f:
return f.readlines()
def main():
filelist = [
"C:UsersT_backDesktopdebug.txt",
"C:UsersT_backDesktoppp.txt"
]
for f in filelist:
debugfile = readfile(f)
for i in debugfile:
print json.dumps(eval(i),sort_keys=True, indent=2, ensure_ascii=False, encoding='utf8')
if name == 'main':
main()
file_name 是个字符串吧, for循环遍历字符串 你拿到的是字母 把for循环去掉