Skip to main content

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

许可证

xy_singleton 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。

捐赠

如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?

Pay-Total

联系方式

微信: yuyangiit
邮箱: yuyangit.0515@qq.com

Project details


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.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

xy_singleton-1.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file xy_singleton-1.0.2.tar.gz.

File metadata

  • Download URL: xy_singleton-1.0.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for xy_singleton-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f45370cb79904e0f5e60011714ed348d595f25844e153e36df4339d5771b1a75
MD5 c5b1cc95acad92a1ea7e6487b457f03e
BLAKE2b-256 e7c46691d52f8ff217008caf010e56a8aa25ffecd12a6f02b82f1eec4dba2b1f

See more details on using hashes here.

File details

Details for the file xy_singleton-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xy_singleton-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b847fe4879c4440db95d4c21fb6c732dd5975202260bcc8ad389113ac1cdcda
MD5 5229b7dd2ea5eda0552fbd93d9056b2e
BLAKE2b-256 bf471eb969f5639643c797454961d29e7d25af1db077a5c0556bd78e4ac8d700

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page