随笔分类 - Python
摘要:__format__ 在format(object,format_spec:str), f-string, ''.format()生效 format_spec [[fill]align][sign][#][0][minimumwidth][.precision][type] class Superf
阅读全文
摘要:import time def dubious(): print(f"\033[32;40;7m{'dubious start'}\033[0m") while True: send_value = yield if send_value is None: break commence = time
阅读全文
摘要:def alarm(item: list): match item: case [time, action]: print(f'{time} {action}') case [time, *actions]: for action in actions: print(f'^^ {time} {act
阅读全文
摘要:import pandas as pd df = pd.DataFrame(data={'id': [1, 2, 3], 'name': ['a', 'b', 'c']}) print(df) df.to_excel('z.xlsx') import pandas as pd df = pd.Dat
阅读全文
摘要:生产杯子 import time, logging, threading FORMAT = '%(asctime)s %(threadName)s %(thread)d %(message)s' logging.basicConfig(level=logging.INFO, format=FORMA
阅读全文
摘要:import logging FORMAT = '%(asctime)-15s\tThread: %(threadName)s %(thread)d %(message)s' logging.basicConfig(format=FORMAT, level=logging.WARNING, date
阅读全文
摘要:从低位依次打印,并计算位数 n = int(input('number: ')) count = 0 while True: print(n % 10) n = n // 10 count += 1 if n == 0: break print('number of digits: ', count
阅读全文
摘要:import sys, threading, tkinter,time def stop(window): # window.destroy() window.quit() sys.exit(0) window = tkinter.Tk() window.title('invariant!') wi
阅读全文
摘要:json.dumps(data,ensure_ascii=False,indent=4,sort_keys=True,skipkeys=True,separators=(',',': ')) try: b(1,0) except Exception as e: logging.exception(s
阅读全文
摘要:import os, zipfile def deflate(paths, zip_path): z = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, allowZip64=True, compresslevel=9) for path i
阅读全文
摘要:paramiko基于SSH连接ssh Server执行操作(SSHClient远程连接,SFTPClient上传下载) pip install paramiko 简单示例 import paramiko ssh = paramiko.SSHClient() # 创建ssh客户端 know_hosts
阅读全文
摘要:os.chmod(path:Union[int,str,bytes,PathLike[str],PathLike[bytes]],mode:int,dir_fd:Optional[int],follow_symlinks:bool) -> Nonemode 采用 0o7777表示法 os.chmod
阅读全文
摘要:import os, time from PyPDF2 import PdfFileReader, PdfFileWriter def get_file_list(path): file_list = [os.path.join(root, filepath) for root, dirs, fil
阅读全文
摘要:import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column,Integer,String,Float,Enum,Date from sqlalchemy
阅读全文
摘要:from wsgiref.simple_server import make_server from webob import Response, Request, exc, dec import re, traceback, logging class Dict2Obj(object): def
阅读全文
摘要:import pymysql from pymysql.cursors import DictCursor # class Field: # def __init__(self,name,column=None,chief=False,unique=False,index=False,nullabl
阅读全文
摘要:import pymysql from pymysql.cursors import DictCursor from queue import Queue import threading class Pool: def __init__(self,size,*args,**kwargs): sel
阅读全文
摘要:class Genre: def __init__(self,title,mold): self.title=title self.mold=mold def __get__(self,instance,owner): print('__get__',self,instance,owner) ret
阅读全文
摘要:import logging,traceback,sys logging.basicConfig(level=logging.WARNING,filename='c:/uiop.txt',filemode='a', format='%(lineno)s %(pathname)s %(asctime)
阅读全文