Python单例的几种实现方式
Project description
xy_singleton
说明
单例工具
源码仓库
安装
pip install xy_singleton
使用
python脚本
from xy_singleton.Decorators import singleton, Singleton
@singleton
class Cls_0(object):
count = 0
def __init__(self):
pass
@Singleton
class Cls_1(object):
count = 0
def __init__(self):
pass
Cls_0().count = 10
Cls_0().count
# 10
Cls_0().count = 11
# 11
Cls_1().count = 10
# 10
Cls_1().count = 11
Cls_1().count
# 11
from xy_singleton.Singleton import CallSingleton, NewSingleton
class Foo_0(metaclass=CallSingleton):
count = 0
Foo_0().count = 10
Foo_0().count
# 10
Foo_0().count = 11
Foo_0().count
# 11
class Foo_1(Singleton):
count = 0
Foo_1().count = 10
Foo_1().count
# 10
Foo_1().count = 11
Foo_1().count
# 11
捐赠
如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?
联系方式
微信: yuyangiit
邮箱: 845262968@qq.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xy_singleton-1.0.1.tar.gz
(3.6 kB
view details)
Built Distribution
File details
Details for the file xy_singleton-1.0.1.tar.gz
.
File metadata
- Download URL: xy_singleton-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 758266769d40a36b7884ca1cd28f498f7e73c377a3605b88fe28a75c76fe6914 |
|
MD5 | 2cdc933da71ade46248d52e3b5a80c6d |
|
BLAKE2b-256 | cdbf9e3dab61706fe3512447c48e6c1f1e305f55e9f5a0e8b31d3ac3727cd350 |
File details
Details for the file xy_singleton-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: xy_singleton-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc47ee0e9936cd48d73c5b3b15a25ed8a1ef1e5ac0c1689ed1a0ea558edfb28c |
|
MD5 | 11ca2bc7c717176fcd78a73b5634263c |
|
BLAKE2b-256 | 1634b9b6a3eebfc5cda5892f881c1473a1762ca185ea96e3cb8e6067f73121f8 |