随笔分类 -  Python

1 2 3 4 5 ··· 7 下一页
摘要:data = '[{"foo": "bar", "foo": "baz", "b": 99}]' json.loads(data, object_hook=print) json.loads(data, object_pairs_hook=print) 阅读全文
posted @ 2023-06-13 14:43 ascertain 阅读(44) 评论(0) 推荐(0) 编辑
摘要:import asyncio import sys class AsyncContextManager: async def __aenter__(self): return self async def __aexit__(self, exc_type, exc_val, exc_tb): pri 阅读全文
posted @ 2023-06-06 14:08 ascertain 阅读(82) 评论(0) 推荐(0) 编辑
摘要:connection import psycopg2 from psycopg2 import Error, connection, cursor conn: connection | None = None c1: cursor | None = None try: conn = psycopg2 阅读全文
posted @ 2023-04-29 21:47 ascertain 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Pool 使用pool正确方法: 从pool取connection,使用完close(), 底层CMySQLConnection会return到deque, 此时从pool中得到的PooledMySQLConnection底层_cnx变为None 阅读全文
posted @ 2023-04-28 14:27 ascertain 阅读(10) 评论(0) 推荐(0) 编辑
摘要:contra-variance from typing import Callable class Food: ... class Meat(Food): ... class Animal: def eat(self, food: Food): ... class Dog(Animal): def 阅读全文
posted @ 2023-04-24 16:34 ascertain 阅读(43) 评论(0) 推荐(0) 编辑
摘要:keyword must be strings 阅读全文
posted @ 2023-04-21 00:59 ascertain 阅读(15) 评论(0) 推荐(0) 编辑
摘要:def get_public_ip(): from urllib.request import urlopen import re as r d = urlopen('http://checkip.dyndns.com').read() return r.compile(r'(\d+\.\d+\.\ 阅读全文
posted @ 2023-04-07 16:24 ascertain 阅读(11) 评论(0) 推荐(0) 编辑
摘要:'import *' only allowed at module level When Python compiles code it needs a determined number of local variables, The number of variables that import 阅读全文
posted @ 2023-04-01 10:06 ascertain 阅读(14) 评论(0) 推荐(0) 编辑
摘要:method str.format_map(self, mapping), 直接传mapping, 可overwrite __missing__ 阅读全文
posted @ 2023-03-31 12:32 ascertain 阅读(12) 评论(0) 推荐(0) 编辑
摘要:decimal_to_binary def decimal_to_binary(v: float, precison: int = 6) -> str: if v == 0: return '0b0' binary = '' integral = int(v) # integral part man 阅读全文
posted @ 2023-03-31 11:35 ascertain 阅读(12) 评论(0) 推荐(0) 编辑
摘要:正常情况fromisoformat都能处理 astimezone(self,tz=None) convert to aware datetime use replace(miscrosecond=0) 阅读全文
posted @ 2023-03-28 23:30 ascertain 阅读(45) 评论(0) 推荐(0) 编辑
摘要:raise from try: try: 1 / 0 except ZeroDivisionError as e: raise Exception("with_traceback") from e except Exception as e: print(e, e.__cause__, type(e 阅读全文
posted @ 2023-03-28 16:10 ascertain 阅读(38) 评论(0) 推荐(0) 编辑
摘要:s1 = '[{(b)}][[]]' s2 = '[{(b}][[]]' def brackets_match(s: str) -> bool: opening_brackets = '([{' closing_brackets = ')]}' nexus = {')': '(', ']': '[' 阅读全文
posted @ 2022-11-30 19:39 ascertain 阅读(105) 评论(0) 推荐(0) 编辑
摘要:A stack is a linear data structure that stores items in a last-in-first-out LIFO or first-in-last-out FILO manner, In stack, a new element is added at 阅读全文
posted @ 2022-11-30 19:15 ascertain 阅读(26) 评论(0) 推荐(0) 编辑
摘要:判断一个整数是否为完全立方数 cubic number: import math cubical = int(input('number: ')) def is_cubical(cubical: int): n = math.ceil(pow(cubical.__abs__(), 1 / 3)) # 阅读全文
posted @ 2022-11-30 00:05 ascertain 阅读(37) 评论(0) 推荐(0) 编辑
摘要:import typing class Node: def __init__(self, value): self.value = value self.prev = None self.next = None def __repr__(self): return f'Node({self.valu 阅读全文
posted @ 2022-11-10 12:53 ascertain 阅读(16) 评论(0) 推荐(0) 编辑
摘要:import os, sys from stat import * from typing import Callable def visit_file(file): print('visiting', file) def walktree(top, callback: Callable): pri 阅读全文
posted @ 2022-11-10 11:51 ascertain 阅读(20) 评论(0) 推荐(0) 编辑
摘要:def _convert_mode(mode: int): if not 0 <= mode <= 0o777: raise RuntimeError res = '' for v in range(0, 9): if mode >> v & 1: match v % 3: case 0: res 阅读全文
posted @ 2022-11-10 01:55 ascertain 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-11-04 10:28 ascertain 阅读(6) 评论(0) 推荐(0) 编辑
摘要:https://phrase.com/blog/posts/beginners-guide-to-locale-in-python/ 阅读全文
posted @ 2022-11-02 15:42 ascertain 阅读(22) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 7 下一页
点击右上角即可分享
微信分享提示