摘要: import time print(time.strftime('%Y/%m/%d %H:%M:%S', time.localtime())) # 2022/06/27 20:55:56 阅读全文
posted @ 2022-06-27 20:58 xuecl 阅读(13) 评论(0) 推荐(0) 编辑
摘要: lists = [1, 2, 3, 4, 5, 6, 7] print(list(filter(lambda x: x > 4, lists))) # [5, 6, 7] print(list(map(lambda x: x > 4, lists))) # [False, False, False, 阅读全文
posted @ 2022-06-27 20:42 xuecl 阅读(47) 评论(0) 推荐(0) 编辑
摘要: dic = dict() def add_two_dimensional_dictionary(old_dict,key_a,key_b,value): if key_a in old_dict: old_dict[key_a].update({key_b:value}) else: old_dic 阅读全文
posted @ 2022-06-22 23:19 xuecl 阅读(40) 评论(0) 推荐(0) 编辑
摘要: def get_last_line(file_name): offset = -10 with open(file_name, 'rb') as f: # 读取方式要以字节读取 while 1: """ f.seek(off, whence=0):从文件中移动off个操作标记(文件指针),正往结束方 阅读全文
posted @ 2022-06-22 23:03 xuecl 阅读(88) 评论(0) 推荐(0) 编辑
摘要: ip2long = lambda x: sum([256 ** j * int(i) for j, i in enumerate(x.split('.')[::-1])]) long2ip = lambda x: '.'.join(['{:0>3d}'.format(x // (256 ** i) 阅读全文
posted @ 2022-03-10 22:47 xuecl 阅读(180) 评论(0) 推荐(0) 编辑
摘要: ip2long = lambda x: sum([256 ** j * int(i) for j, i in enumerate(x.split('.')[::-1])]) long2ip = lambda x: '.'.join(['{:0>3d}'.format(x // (256 ** i) 阅读全文
posted @ 2022-03-10 22:34 xuecl 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 大文件直接用read()函数会内存溢出 解决办法 1. 一行一行的取 with open('t1.txt') as f: while True: data = f.readline() # 判断文件是否结束 if not data: break # 优化版 with open('t1.txt') a 阅读全文
posted @ 2022-03-01 20:44 xuecl 阅读(830) 评论(0) 推荐(0) 编辑
摘要: concat(a, b) 用来连接参数a和参数b, 参数a和b可以是固定的字符串,也可以是变量,也可以是通配符('%'代表0个或多个字符,'_'代表任意一个字符) e1: e2: e3: replace(a,b,c) e1: mid(a,b[,c]) 参考: https://sqlzoo.net/w 阅读全文
posted @ 2022-02-22 22:21 xuecl 阅读(516) 评论(0) 推荐(0) 编辑
摘要: 先安装fake_useragent模块 pip install fake_useragent 代码 from fake_useragent import UserAgent ua = UserAgent() ua.ie # Mozilla/5.0 (Windows; U; MSIE 9.0; Win 阅读全文
posted @ 2022-01-08 16:56 xuecl 阅读(195) 评论(0) 推荐(0) 编辑
摘要: ##requirements.txt文件记录了项目所依赖的包以及版本,方便在新环境导入 生成requirements.txt文件 pip freeze > requirements.txt 在新环境导入依赖包 pip install -r requirements.txt 阅读全文
posted @ 2021-12-19 11:46 xuecl 阅读(30) 评论(0) 推荐(0) 编辑