按时间 排序 :http://blog.csdn.net/stan_pcf/article/details/51969878
关键词重要性排序 :keydict = sorted(词典名.iteritems(), key=lambda d: d[1], reverse=True) #d[0]:按key排序 d[1]:按value排序
加载json文件
json文件一定是utf8无BOM格式否则报错
def load_datas():
basePath = path.abspath(path.dirname(__file__)) #前两句在falsk主文件中必须使用
uploadPath = path.join(basePath, 'files/history.json')
f = file(uploadPath)
jsonDatas = json.load(f)
加载文件多使用with
https://www.ibm.com/developerworks/cn/opensource/os-cn-pythonwith/
with open(r'somefileName') as somefile:
for line in somefile:
print line
# ...more code