一、字符串拼接+排序
word='''awfesdafhjkcasadckjsdackjsadvcnksausafdsch ''' b='SufhwrifjiEIJFDIEJDIej' list1 = list(word+b) while '\n' in list1: list1.remove('\n') list2 = sorted(list1) print(''.join(list2))
二、 Python装饰器实现对异常代码进行监控
https://www.cnblogs.com/leiziv5/p/8205580.html
import datetime,time,random def make(func): def mak(*args,**kwargs): try: func(*args,**kwargs) except: with open('except.txt','a+') as f: except_time=datetime.datetime.now() f.writelines(except_time.strftime('%Y-%m-%d %H:%M:%S')+'\n') f.close() with open('except.txt','rb') as m: try: date=m.readlines()[-5].decode('utf-8') ne=(date.split('\r\n')[0]) f1=datetime.datetime.strptime(ne,'%Y-%m-%d %H:%M:%S') if (except_time-f1).seconds<6: print('异常!!!fail') else: print('正常!') m.close() except: print('越界代表着我们的实验是成功的') return mak @make def beijing(i,m): print(i/m) if __name__=="__main__": while True: f=random.choice([0,1,2,3]) n=random.choice([0,1,2,3]) beijing(f,n) time.sleep(0.3)