# sys模块# import sys# sys.path# sys.argv# sys.exit() # 脚本退出# print('[%s]'%('#'*1))# print('[%s]'%('#'*2))# print('[%s]'%('#'*3))# print('[%s]'%('#'*4))# print('[%s]'%('#'*5))# print('[%-50s]'%('#'*1))# print('[%-50s]'%('#'*2))# print('[%-50s]'%('#'*3))# print('[%-50s]'%('#'*4))# print('[%-50s]'%('#'*5))'''[#][##][###][####][#####][# ][## ][### ][#### ][##### ]'''# print('%d%%'%30) # 30%# print('[%%-%ds]'%50)# print(('[%%-%ds]'%50)%('#'*1))# print(('[%%-%ds]'%50)%('#'*2))# print(('[%%-%ds]'%50)%('#'*3))# print(('[%%-%ds]'%50)%('#'*4))# print(('[%%-%ds]'%50)%('#'*5))'''[%-50s][# ][## ][### ][#### ][##### ]'''# def progress(percent,width=50):# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s'%show_str,end='')# progress(0.1)# progress(0.2)# progress(0.3)# progress(0.4)# progress(0.5)'''[##### ][########## ][############### ][#################### ][######################### ]'''# def progress(percent,width=50):# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s'%show_str,end='')# progress(0.1)# progress(0.2)# progress(0.3)# progress(0.4)# progress(0.5)'''[######################### ]'''# def progress(percent,width=50):# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s %d%%'%(show_str,int(100*percent)),end='')# progress(0.1)# progress(0.2)# progress(0.3)# progress(0.4)# progress(0.5)'''[######################### ] 50%'''# import time# def progress(percent,width=50):# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s %d%%'%(show_str,int(100*percent)),end='')# recv_size=0# total_size=198749# while recv_size < total_size:# time.sleep(0.1)# recv_size+=1034# progress(recv_size/total_size)'''[##################################################] 100%'''# import time# def progress(percent,width=50):# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s %d%%'%(show_str,int(100*percent)),end='')# recv_size=0# total_size=10241# while recv_size < total_size:# time.sleep(0.1)# recv_size+=1024# progress(recv_size/total_size)'''[######################################################] 109%'''# import time# def progress(percent,width=50):# if percent >= 1:# percent=1# show_str=('[%%-%ds]'%width)%('#'*int(width*percent))# print('\r%s %d%%'%(show_str,int(100*percent)),end='')# recv_size=0# total_size=10241# while recv_size < total_size:# time.sleep(0.1)# recv_size+=1024# progress(recv_size/total_size)'''[##################################################] 100%'''# 序列化可以将内存中的数据结构保存下来,字典 ,列表,元组,字符串...# dic={'a':1}# with open('db.txt','w',encoding='utf-8')as f:# f.write(str(dic))# with open('db.txt','r',encoding='utf-8')as f:# dic=eval(f.read())# print(dic['a'])'''1''''''内存中结构化的数据<->格式json<->字符串<->保存到文件中或基于网络传输'''# eval("[null,false,1]")# [null,false,1]# import json# dic={'a':1}# res=json.dumps(dic)# print(res,type(res))'''{"a": 1} <class 'str'>'''# import json# dic={'a':1}# res=str(dic)# print(res,type(res))'''{'a': 1} <class 'str'>'''# import json# x=None# print(json.dumps(x))'''null'''# import json# user={'name':'egon','age':18,'nb':True}# # with open('user.json','w',encoding='utf-8')as f:# # f.write(json.dumps(user))# json.dump(user,open('user_new.json','w',encoding='utf-8'))# import json,time# user={'name':'egon','age':18,'nb':True}# with open('user.json','w',encoding='utf-8')as f:# f.write(json.dumps(user))# students=['egon','wer','axjl']# json.dump(students,open('students.json','w',encoding='utf-8'))# time.sleep(500)'''别的文件拿过来的import jsonwith open('user.json','r',encoding='utf-8')as f: user=json.loads(f.read()) print(user['name']) # egonuser=json.load(open('user.json','r',encoding='utf-8'))print(user['age']) # 18print(user['nb']) # True'''# json_str='{"count":1}'# print(json.loads(json_str))# print(json.loads(json_str)['count'])'''{'count': 1}1'''# pickle# 可以识别python的所有数据类型# 但是不能跨平台# import pickle,json# s={1,2,3,4}# # print(json.dumps(s))# print(pickle.dumps(s))'''b'\x80\x03cbuiltins\nset\nq\x00]q\x01(K\x01K\x02K\x03K\x04e\x85q\x02Rq\x03.''''# with open('s.pkl','wb')as f:# f.write(pickle.dumps(s))# pickle.dump(s, open('s.pkl','wb'))'''import picklewith open('s.pkl','rb')as f: s=pickle.loads(f.read()) print(s,type(s)) {1, 2, 3, 4} <class 'set'>''''''import pickles=pickle.load(open('s.pkl','rb'))print(s,type(s)){1, 2, 3, 4} <class 'set'>'''
来源:https://www.cnblogs.com/0B0S/p/12040544.html