偏函数

简介 简单的理解偏函数,它是对原始函数的二次封装,是将现有函数的部分参数预先绑定为指定值,从而得到一个新的函数,该函ă

iohannes iohannes Published on 2025-03-17

浅拷贝和深拷贝

在Python中,浅拷贝(shallow copy)意味着创建一个新的对象,但它包含的是对原始对象中项的引用。如果原对象中的项是不可变的(如整数、字符串、元

iohannes iohannes Published on 2025-03-17

限制类的属性

BaseModel from pydantic import BaseModel # 定义类 class User(BaseModel): id: int name:str sex:str age:int def myFunc(self):

iohannes iohannes Published on 2025-03-14

线程间通信queue

以生产者和消费者为例,说明线程间通信 Queue是线程间安全类, queue.Queue 类内部使用一个列表(或其他容器)来存储项目,并使用一个互斥锁(

iohannes iohannes Published on 2025-03-14

线程锁

在Python的threading模块中,Lock对象提供了基本的线程锁定功能。threading.Lock基于底层的操作系统原语(如mutex)来实现。当一个线程尝试获取一个已经"

iohannes iohannes Published on 2025-03-14

延迟绑定问题

延迟绑定的问题 def create_multipliers(): return [lambda x : i * x for i in range(5)] for multiplier in create_multipliers(): print(multiplier(2)) 输出

iohannes iohannes Published on 2025-03-14

运行外部py文件

要运行的py文件 # b.py from a import * def funb(): print("fun b") funa() if __name__ == "__main__": funb() 引用的同目录文件

iohannes iohannes Published on 2025-03-14

== 和 is

a = 'hello world' b = 'hello world' a == b #返回True a is b #返回False is 判断是否是一个ID == 判断内容是否相等

iohannes iohannes Published on 2025-03-14

cachetools

安装 pip3 install cachetools 常见缓存分类 class cachetools.Cache(maxsize, getsizeof=None) class cachetools.LRUCache(maxsize, getsizeof=None). Least Recently U

iohannes iohannes Published on 2025-03-14

class to json string

import json from json import JSONEncoder class Employee: def __init__(self, name, salary, address): self.name = name self.salary

iohannes iohannes Published on 2025-03-14
Previous Next