随笔分类 -  Python

摘要:# 使用list() bytesDate = '源数据'.encode() print(bytesDate, list(bytesDate)) 阅读全文
posted @ 2022-09-03 03:16 三个零 阅读(333) 评论(0) 推荐(0) 编辑
摘要:import urllib3 # 禁用警告 urllib3.disable_warnings() # urllib3 不验证ssl _pool_params = dict(cert_reqs='CERT_NONE', assert_hostname=False) url = 'https://www 阅读全文
posted @ 2022-09-02 02:59 三个零 阅读(308) 评论(0) 推荐(0) 编辑
摘要:安装 pip install pillow 添加文字水印 from PIL import Image, ImageDraw, ImageFont img_name = '1.jpg' text = '博客园 @三个零' img = Image.open(img_name) draw = ImageD 阅读全文
posted @ 2022-06-29 02:54 三个零 阅读(454) 评论(0) 推荐(0) 编辑
摘要:安装 pip install docx2pdf 使用 from docx2pdf import convert # doc 文件 需要先转为 docx 文件(一般情况下、直接修改后缀名、不会对原文件有影响) inputFile = '1.docx' # 要转换的文件:已存在 outputFile = 阅读全文
posted @ 2022-06-24 01:34 三个零 阅读(3596) 评论(0) 推荐(0) 编辑
摘要:pprint 官方文档 https://docs.python.org/3/library/pprint.html from pprint import pprint data_json = {'a': "923c550d262a468237e34777b6279fdf", 'b': "a3c1f8 阅读全文
posted @ 2022-06-18 02:19 三个零 阅读(29) 评论(0) 推荐(0) 编辑
摘要:""" 将 各种格式的 cookie 转为 字典格式 """ def cookie_factory(ck_str=None): cookie_dict = {} # 从浏览器 抓包 复制过来的 cookie 字符串 if ck_str: for cookie in ck_str.split(';') 阅读全文
posted @ 2022-05-25 03:51 三个零 阅读(627) 评论(0) 推荐(0) 编辑
摘要:通过 Traceback 能得知运行异常的位置、原因 当程序没有捕获异常、运行异常时 会自动调用 Traceback 进行异常回溯 捕获异常 当程序捕获异常时 不会自动调用 Traceback 进行异常回溯 def run(): try: print('Before') print(1 / 0) p 阅读全文
posted @ 2022-03-29 03:05 三个零 阅读(366) 评论(0) 推荐(0) 编辑
摘要:将当前环境中已安装的三方库及对应版本 输出到文本中 pip freeze > requirements.txt 卸载当前环境中所有安装的库 pip uninstall -r requirements.txt -y 安装文本中 对应版本的所有三方库 pip install -r requirement 阅读全文
posted @ 2022-03-21 03:00 三个零 阅读(224) 评论(0) 推荐(0) 编辑
摘要:安装 pip install scrapy 导入 from scrapy.selector import Selector 待提取文本 content = """ <table class="tab"> <tr class="cdf"> 1<a>tr下的第一个a标签</a>2 3<td class= 阅读全文
posted @ 2022-03-19 01:58 三个零 阅读(644) 评论(0) 推荐(0) 编辑
摘要:关闭不安全请求警告 import urllib3 urllib3.disable_warnings() import requests import urllib3 urllib3.disable_warnings() response = requests.get('https://www.bai 阅读全文
posted @ 2022-03-13 19:54 三个零 阅读(138) 评论(0) 推荐(0) 编辑
摘要:导入 import pickle 转换 data = [{'title': 't1', 'url': 'one'}, {'title': 't2', 'url': 'two'}] data_dumps = pickle.dumps(data) print(type(data_dumps)) # <c 阅读全文
posted @ 2022-03-12 02:38 三个零 阅读(2989) 评论(0) 推荐(1) 编辑
摘要:当队列为空时,执行get(),不会报异常 会进入阻塞状态,直到队列中有东西可取为止 from queue import Queue taskQueue = Queue() taskQueue.put('queue task 1') print(f'队列长度:{taskQueue.qsize()}') 阅读全文
posted @ 2022-03-08 02:15 三个零 阅读(804) 评论(0) 推荐(0) 编辑
摘要:import os # os.path.split 分割路径 path1 = r'e:\tool\read.txt' print(os.path.split(path1)) # ('e:\\tool', 'read.txt') print(os.path.splitext(path1)) # ('e 阅读全文
posted @ 2022-03-05 02:08 三个零 阅读(223) 评论(0) 推荐(0) 编辑
摘要:单进程单线程 import time def production(): """ 间隔一秒,模拟一秒生产一个任务,生产10个任务 :return: 生产完毕,返回需要消费的任务 """ _tasks = 0 while _tasks < 10: time.sleep(1) _tasks += 1 p 阅读全文
posted @ 2022-03-04 13:31 三个零 阅读(120) 评论(0) 推荐(0) 编辑
摘要:import platform plat = platform.system().lower() if plat == 'windows': print('windows系统') elif plat == 'linux': print('linux系统') 阅读全文
posted @ 2022-02-11 03:06 三个零 阅读(3708) 评论(0) 推荐(0) 编辑
摘要:sys.argv 一个从程序外部获取参数的桥梁 参数是从程序外部输入的 而非代码本身的什么地方 类型为List 用法 sys.argv[0]表示代码本身文件路径 从外部来运行程序并给出参数 import sys try: print(type(sys.argv), sys.argv) print(' 阅读全文
posted @ 2021-09-25 01:59 三个零 阅读(270) 评论(0) 推荐(0) 编辑
摘要:pyinstrument会把代码里运行耗时的部分给你找出来 使用 pip install pyinstrument import time from pyinstrument import Profiler def sleep_time(): time.sleep(2) print('end') p 阅读全文
posted @ 2021-09-19 23:42 三个零 阅读(377) 评论(0) 推荐(0) 编辑
摘要:###requests stream=True import time import requests download_url = '' start_time = time.time() file_name = 'video.mp4' # 文件名称 # 以流形式下载文件 result = requ 阅读全文
posted @ 2021-09-15 01:40 三个零 阅读(1543) 评论(0) 推荐(0) 编辑
摘要:import time start_time = time.time() # 内容总大小 content_size = 100 # 进度条字符 char_str = '>' # 进度条字符长度 char_long = 50 for size in range(content_size + 1): # 阅读全文
posted @ 2021-09-14 01:25 三个零 阅读(318) 评论(0) 推荐(0) 编辑
摘要:常用标签 if/elif/else 可以使用and/or/in/not/==/!=/<=/>= ifequal/ifnotequal {% ifequal name 'DoubleU' %} DoubleU来了 {% endifequal %} for...in... forloop.counter 阅读全文
posted @ 2021-08-10 20:39 三个零 阅读(105) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示