随笔分类 -  python(杂)

记录遇到的python开发相关的问题
摘要:python ssh 客户端 阅读全文
posted @ 2024-11-19 09:57 干炸小黄鱼 阅读(2) 评论(0) 推荐(0) 编辑
摘要:产品新提了个需求, 要求排序后Null值不管是正序还是反序都排在最后或者最前 项目使用sqlalchemy, 使用 nullslast, nullsfirst 有些版本也是用nulls_first, nulls_last # Null永远在后 from sqlalchemy import nulls 阅读全文
posted @ 2024-10-11 17:11 干炸小黄鱼 阅读(41) 评论(0) 推荐(0) 编辑
摘要:version: '3.1' services: db: image: postgres:13.1 container_name: com_db environment: POSTGRES_USER: root POSTGRES_PASSWORD: db123 POSTGRES_DB: db vol 阅读全文
posted @ 2024-09-20 10:51 干炸小黄鱼 阅读(6) 评论(0) 推荐(0) 编辑
摘要:import io import os import string from random import choice, randrange, sample from PIL import Image, ImageDraw, ImageFont def generate_captcha(): img 阅读全文
posted @ 2024-09-11 19:24 干炸小黄鱼 阅读(6) 评论(0) 推荐(0) 编辑
摘要:有个需求需要对数据进行分组 然后对分组后的组内数据继续排序 from itertools import groupby # 示例数据 data = [ {'a': "攻击队1", 'b': '张三', 'c': 3}, {'a': "攻击队1", 'b': '张三1', 'c': 1}, {'a': 阅读全文
posted @ 2024-09-06 11:12 干炸小黄鱼 阅读(9) 评论(0) 推荐(0) 编辑
摘要:有个场景, 需要展示ip的经纬度 和所属省市 使用开源的地理库 geoip2 ,需要去官网下载一个GeoLite2-City.mmdb包, 差不多50M左右 先安装扩展 pip install geoip2 示例代码 import geoip2.database # 指定你的 GeoLite2 数据 阅读全文
posted @ 2024-09-03 17:20 干炸小黄鱼 阅读(268) 评论(0) 推荐(0) 编辑
摘要:apscheduler.schedulers.blocking python定时器 阅读全文
posted @ 2024-08-12 14:30 干炸小黄鱼 阅读(13) 评论(0) 推荐(0) 编辑
摘要:简单的 python web项目docker-compose.yml示例, 包含flask初始化db等命令; 阅读全文
posted @ 2024-08-12 10:30 干炸小黄鱼 阅读(21) 评论(0) 推荐(0) 编辑
摘要:开源第三方库:https://sliverpy.readthedocs.io/en/latest/getting-started.html#connect-example 代码示例: import os import asyncio from sliver import SliverClientCo 阅读全文
posted @ 2024-08-07 11:51 干炸小黄鱼 阅读(15) 评论(0) 推荐(0) 编辑
摘要:定义一个统一的schema类对提交的业务参数进行格式和数据约束非常有必要, 下面使用 pydantic 来封装此工具; import logging from pydantic import BaseModel, ValidationError, root_validator class Pydan 阅读全文
posted @ 2024-07-31 16:17 干炸小黄鱼 阅读(178) 评论(0) 推荐(0) 编辑
摘要:基础数据 LONGITUDE_LATITUDE = { "110000": {"name": "北京市", "latitude": 39.904989, "longitude": 116.405285}, "110101": {"name": "东城区", "latitude": 39.917544 阅读全文
posted @ 2024-07-26 16:46 干炸小黄鱼 阅读(58) 评论(0) 推荐(0) 编辑
摘要:flask 迁移数据库时可能会遇到找不到版本的问题 export FLASK_APP=run.py flask db migrate 执行上述命令时正常会提示加了哪些字段,删除了哪些字段 但是有时候会提示: ERROR [flask_migrate] Error: Can't locate revi 阅读全文
posted @ 2024-07-25 14:23 干炸小黄鱼 阅读(223) 评论(0) 推荐(0) 编辑
摘要:背景: 有个一个组织机构. 并没有设计父级id, 只有id, title, nature 三个字段, nature=1/2/3/4 分别表示级几级单位; 现在要模糊查询本级, 上级, 上上级, 上上上级的title中包含 特定字符的记录;使用sqlalchemy递归查询,下面代码没调试,不保证运行, 阅读全文
posted @ 2024-07-15 10:05 干炸小黄鱼 阅读(49) 评论(0) 推荐(0) 编辑
摘要:工具类cvs util.py #!/usr/bin/env python # -*- coding: utf-8 -*- import csv import codecs import io class UTF8Recoder: """ Iterator that reads an encoded 阅读全文
posted @ 2024-07-11 09:16 干炸小黄鱼 阅读(25) 评论(0) 推荐(0) 编辑
摘要:需求; 统计不同组织下的成绩风险等级类型个数; attacker_group = ( db.session.query(ReportResult, Report, Organization) .join(Report, Report.id == ReportResult.report_id) .jo 阅读全文
posted @ 2024-06-28 15:49 干炸小黄鱼 阅读(95) 评论(0) 推荐(0) 编辑
摘要:常用匹配规则 . 除换行符以外的所有字符。 ^ 字符串开头。 $ 字符串结尾。 \d,\w,\s 匹配数字、字符、空格。 \D,\W,\S 匹配非数字、非字符、非空格。 [abc] 匹配 a、b 或 c 中的一个字母。 [a-z] 匹配 a 到 z 中的一个字母。 [^abc] 匹配除了 a、b 或 阅读全文
posted @ 2024-06-03 10:24 干炸小黄鱼 阅读(11) 评论(0) 推荐(0) 编辑
摘要:问题背景: 有个pg查询的sql很慢, 需要优化, 打印出原始sql来explain: from sqlalchemy.dialects import postgresql query = Config.query.all() try: # 引入方言, literal_binds 指定参数全部替换 阅读全文
posted @ 2024-04-01 19:26 干炸小黄鱼 阅读(95) 评论(0) 推荐(0) 编辑

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