leafcoder 最近的时间轴更新
leafcoder's repos on GitHub
Python · 155 人关注
django-covid19
实时接口获取中国各个城市、省份、国家的新型冠状肺炎(新冠肺炎 / 2019-nCoV / Covid-19)。疫情数据以及整体统计详情,新增美国各州统计、每日疫情数据 API。爬虫实时追踪新冠疫情变化,数据来自丁香园和 covidtracking.com。数据大屏示例:http://ncov.leafcoder.cn/demo/ 项目文档:http://ncov.leafcoder.cn/docs/
Python · 2 人关注
litefs
Build a web server framework using Python. Litefs was developed to implement a server framework that can quickly, securely, and flexibly build Web projects. Litefs is a high-performance HTTP server. Litefs has the characteristics of high stability, rich functions, and low system consumption.
Python · 2 人关注
ProxyPoolSpider
抓取各大主要的免费代理网站数据,选取可用IP保存入数据库
Python · 1 人关注
EscrowAPI
escrow.com API 接口
0 人关注
aliyun-openapi-python-sdk
Alibaba Cloud SDK for Python
0 人关注
aliyun-oss-python-sdk
Aliyun OSS SDK for Python
Python · 0 人关注
aliyun-tablestore-python-sdk
Aliyun Tablestore (原OTS) Python SDK
Python · 0 人关注
barcode
㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.
0 人关注
c10k
A coroutine-based alternative implementation of the posix thread
0 人关注
country-json
A simple data of the world by country each in JSON format.
Python · 0 人关注
cpinyin
使用 cython 重写 lxneng 的 xpinyin.
Python · 0 人关注
dailyscript
常用脚本,专注解决小问题。
0 人关注
DecryptLogin
DecryptLogin: APIs for loginning some websites by using requests.
0 人关注
django-friendship
Django app to manage following and bi-directional friendships
CSS · 0 人关注
dnsadmin
自用前端框架
0 人关注
dnslib
A Python library to encode/decode DNS wire-format packets
0 人关注
etcd
Distributed reliable key-value store for the most critical data of a distributed system
Python · 0 人关注
eurasia
Automatically exported from code.google.com/p/eurasia
0 人关注
follow-me-install-kubernetes-cluster
和我一步步部署 kubernetes 集群
0 人关注
funcraft
(have) Fun with Serverless(API Gateway & Function Compute)
0 人关注
jumpserver
JumpServer 是广受欢迎的开源堡垒机,是符合 4A 规范的专业运维安全审计系统。
0 人关注
leafcoder
JavaScript · 0 人关注
leafcoder.github.com
叶子
0 人关注
libeio
libeio sync from http://cvs.schmorp.de/libeio/
0 人关注
libev
Full-featured high-performance event loop loosely modelled after libevent
0 人关注
limerc-sdk
Limesurvey Remote Control API SDK
Python · 0 人关注
limesurveyrc2api
LimeSurvey RC2 REST webservices client
Python · 0 人关注
litedb
基于 sqlite3 实现的简单对象数据库
Python · 0 人关注
MovieSpider
爬取电影资源的爬虫
leafcoder

leafcoder

Life is short, use Python.
V2EX 第 528113 号会员,加入于 2021-01-13 13:45:53 +08:00
玩蛇人属蛇。
leafcoder 最近回复了
2021-03-01 10:10:38 +08:00
回复了 capbone 创建的主题 Python Python :如何避免某个函数内的类反复进行实例化?
忽略第 3 条条件可以如下:

class C(object):
pass


class Demo(object):

def __new__(cls, *args, **kwargs):
inst = object.__new__(cls, *args, **kwargs)
if not hasattr(Demo, 'c_inst'):
c_inst = C(*args, **kwargs)
Demo.c_inst = c_inst
inst.c_inst = Demo.c_inst
return inst

def __init__(self, *args, **kwargs):
pass


for i in range(5):
o = Demo()
print(o, o.c_inst)

输出:

>>> (<__main__.Demo object at 0x7f7bd9e95310>, <__main__.C object at 0x7f7bd9e95350>)
>>> (<__main__.Demo object at 0x7f7bd9e95390>, <__main__.C object at 0x7f7bd9e95350>)
>>> (<__main__.Demo object at 0x7f7bd9e95310>, <__main__.C object at 0x7f7bd9e95350>)
>>> (<__main__.Demo object at 0x7f7bd9e95390>, <__main__.C object at 0x7f7bd9e95350>)
>>> (<__main__.Demo object at 0x7f7bd9e95310>, <__main__.C object at 0x7f7bd9e95350>)
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   935 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 22:34 · PVG 06:34 · LAX 14:34 · JFK 17:34
Developed with CodeLauncher
♥ Do have faith in what you're doing.