随笔分类 -  python

1 2 3 4 5 ··· 12 下一页
摘要:python a={'a':123}b={'b':456}a['x']=bprint(a)b={'b':789}print(a) {'a': 123, 'x': {'b': 456}}{'a': 123, 'x': {'b': 456}} lua local a={} a['a']=123 loca 阅读全文
posted @ 2026-01-12 17:22 papering 阅读(21) 评论(0) 推荐(0)
摘要:strip error · Issue #143185 · python/cpython https://github.com/python/cpython/issues/143185 s = 'bytedance_advertiser'.rstrip('_advertiser')s1 = 'ten 阅读全文
posted @ 2025-12-26 11:22 papering 阅读(17) 评论(0) 推荐(0)
摘要:def _gzip_string(data): try: return gzip.compress(data) except AttributeError: import StringIO buf = StringIO.StringIO() fd = gzip.GzipFile(fileobj=bu 阅读全文
posted @ 2025-11-07 15:11 papering 阅读(5) 评论(0) 推荐(0)
摘要:解决 pandas.to_csv 乱码、丢失行和自动换行问题-百度开发者中心 https://developer.baidu.com/article/details/2792989 在使用 pandas.to_csv 函数时,可能会遇到一些问题,如乱码、丢失行和自动换行等。这些问题通常是由于编码格式 阅读全文
posted @ 2025-09-18 17:04 papering 阅读(120) 评论(0) 推荐(0)
摘要:s = ''' [ { label: "苹果", value: "origin_event_data", icon: "icon-a", color: "#409EFF", bgColor: "#ECF5FF", borderColor: "#D9ECFF", }, { label: "橘子", v 阅读全文
posted @ 2025-09-18 10:25 papering 阅读(25) 评论(0) 推荐(0)
摘要:Generics — typing documentation https://typing.python.org/en/latest/reference/generics.html You may have seen type hints like list[str] or dict[str, i 阅读全文
posted @ 2025-09-11 10:50 papering 阅读(11) 评论(0) 推荐(0)
摘要:assert在Python优化模式(-O)下会被全局禁用 应改用显式的if/raise结构抛出业务异常(如ValueError) 翻译 搜索 复制 阅读全文
posted @ 2025-07-17 18:29 papering 阅读(12) 评论(0) 推荐(0)
摘要:import contextlibimport threadingimport timeclass TimeoutException(Exception): passdef raise_exception(): raise TimeoutException("Time out")@contextli 阅读全文
posted @ 2025-06-09 16:20 papering 阅读(20) 评论(0) 推荐(0)
摘要:Python 类变动的钩子方法 from typing import Listclass Field: def __init__(self, name, is_user=False): self.name = name self.is_user = is_user def __str__(self) 阅读全文
posted @ 2024-09-05 18:18 papering 阅读(17) 评论(0) 推荐(0)
摘要:isort https://pycqa.github.io/isort/ isort · PyPI https://pypi.org/project/isort/ Before isort: from my_lib import Object import os from my_lib import 阅读全文
posted @ 2024-08-29 11:26 papering 阅读(24) 评论(0) 推荐(0)
摘要:实践: 测试用例 @dataclasses.dataclassclass TestCase: method: str path: str cid: int data: dict query_str: str resp: dict = dataclasses.field(default_factory 阅读全文
posted @ 2024-08-28 14:42 papering 阅读(16) 评论(0) 推荐(0)
摘要:def defer(msg: str, subject='参数错误'): print('do ') return f'{subject}:{msg}'assert False, defer('66') Python 实现类似于Go语言中的延迟执行语句(defer)|极客笔记 https://deep 阅读全文
posted @ 2024-08-27 17:42 papering 阅读(35) 评论(0) 推荐(0)
摘要:s = 'abcaabc's = s.rstrip('abc') #!/usr/bin/python# -*- coding: UTF-8 -*- random_string = 'this is good ' # 字符串末尾的空格会被删除print(random_string.rstrip()) 阅读全文
posted @ 2024-08-12 14:22 papering 阅读(114) 评论(0) 推荐(0)
摘要:The Art of Graceful Reloading — uWSGI 2.0 documentation https://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html 翻译 搜索 复制 阅读全文
posted @ 2024-07-18 17:48 papering 阅读(28) 评论(0) 推荐(0)
摘要:如果 ensure_ascii 是 true (即默认值),输出保证将所有输入的非 ASCII 字符转义。如果 ensure_ascii 是 false,这些字符会原样输出。 If ensure_ascii is true (the default), the output is guarantee 阅读全文
posted @ 2024-07-12 19:12 papering 阅读(240) 评论(0) 推荐(0)
摘要:变量声明周期 内存释放 翻译 搜索 复制 阅读全文
posted @ 2024-07-11 10:30 papering 阅读(10) 评论(0) 推荐(0)
摘要:numpy判断 import numpy as np nan = float('nan') print(np.isnan(nan)) 翻译 搜索 复制 阅读全文
posted @ 2024-07-05 10:38 papering 阅读(13) 评论(0) 推荐(0)
摘要:Standard Library Types - Pydantic https://docs.pydantic.dev/2.7/api/standard_library_types/#typeddict from pydantic import BaseModelfrom typing import 阅读全文
posted @ 2024-05-30 14:23 papering 阅读(40) 评论(0) 推荐(0)
摘要:l=[{'a':45},{"b":34}]c=0for i in l: i['a']=c*100 c+=1 * 翻译 搜索 复制 阅读全文
posted @ 2024-05-23 20:16 papering 阅读(19) 评论(0) 推荐(0)
摘要:class Test: def __init__(self, totals, uniques, pre): self.totals = totals self.uniques = uniques self.cumulative_sum = totals if pre: self.cumulative 阅读全文
posted @ 2024-05-23 18:38 papering 阅读(21) 评论(0) 推荐(0)

1 2 3 4 5 ··· 12 下一页