Skip to main content

A useless Python library

Project description

UselessLib 说明文档

1. 概述

UselessLib 是一个Python工具库,提供了一系列工具函数。本库采用模块化设计,包含对布尔值、整数、字符串等基础数据类型的判断操作,以及函数执行等功能。

2. 功能模块

2.1 布尔(Bool)操作模块

提供全面的布尔值判断和操作功能:

  • 判断布尔值的真伪状态
  • 生成随机布尔值
  • 获取基础布尔常量

核心功能示例

from cn.xiuxius.uselesslib.bool import is_true, is_false, random_bool

print(is_true(True))  # True
print(random_bool())  # 随机True或False
函数 描述 返回值
is_true(n: bool) 判断是否为True bool
is_false(n: bool) 判断是否为False bool
random_bool() 生成随机布尔值 bool

2.2 整数(Int)操作模块

提供0-100整数的精确判断功能,支持自定义数字匹配:

核心功能示例

from cn.xiuxius.uselesslib.int import is_zero, is_twenty, is_custom_number

print(is_zero(0))  # True
print(is_custom_number(30, 30))  # True

本模块包含从0到100的精确判断函数,如 is_one()is_one_hundred()

2.3 字符串(Str)操作模块

提供字母a-z的大小写敏感/不敏感匹配,支持自定义字符串匹配:

核心功能示例

from cn.xiuxius.uselesslib.str import is_a, is_z_ignore_case, is_custom_str

print(is_a("a"))  # True
print(is_custom_str("Test", "test"))  # False
函数命名规则 示例
is_[a-z] 区分大小写的匹配
is_[a-z]_ignore_case 不区分大小写的匹配

2.4 函数(Fun)操作模块

提供函数执行功能:

  • 带参数/关键字参数执行
  • 带异常概率的执行
  • 多种执行方式封装

核心功能示例

from cn.xiuxius.uselesslib.fun import execute_fun_with_args, execute_fun_with_random_exception

def add(a, b):
    return a + b

execute_fun_with_args(add, 1, 2)  # 3

try:
    execute_fun_with_random_exception(lambda: 1/1, probability=0.1)
except Exception as e:
    print(f"捕获异常: {e}")

2.5 工具(Util)模块

提供系统级功能:

  • 随机打印字符串
  • 异步崩溃机制(用于测试场景)

核心功能示例

from cn.xiuxius.uselesslib.util import random_print_str, async_crash_with_random_time_in_1_minute

random_print_str()  # 输出随机字符串
# async_crash_with_random_time_in_1_minute()  # 谨慎使用

3. 安装与使用

3.1 安装方式

pip install Py-UselessLib

3.2 基础导入

from cn.xiuxius.uselesslib import bool, int, str, fun, util

4. 最佳实践

4.1 布尔运算

from cn.xiuxius.uselesslib.bool import is_true_or_false

result = is_true_or_false(False)  # 安全的布尔判断

4.2 执行一个函数并以probability的概率抛出一个随机异常

from cn.xiuxius.uselesslib.fun import execute_fun_with_random_exception
execute_fun_with_random_exception(lambda: 1/1, probability=0.1)

4.3 自定义匹配

可以自定义的字符串匹配 极高的扩展性和自由度

from cn.xiuxius.uselesslib.str import is_custom_str_ignore_case

match = is_custom_str_ignore_case("Hello", "hello")  # True

6. 许可证

UselessLib 使用 MIT 许可证开放源代码,详情见 LICENSE 文件。

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

py_uselesslib-1.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_uselesslib-1.0.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file py_uselesslib-1.0.1.tar.gz.

File metadata

  • Download URL: py_uselesslib-1.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for py_uselesslib-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a715d8e583a66d5c5b5c47223bcc981cd99c6fbf689acdd574b1e94e7fa61da0
MD5 78d096dd6741abd1f9a883181394d21d
BLAKE2b-256 4648b7ee7ab94245a5c17cf6d3b147d6446c2a83ba7e0c9cf9e699c56018c29b

See more details on using hashes here.

File details

Details for the file py_uselesslib-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_uselesslib-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for py_uselesslib-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8660bff326c8ea5f32d22d17a6c72384d58358c062ee2b9bc012a4095fa81333
MD5 bbd0e77e56dbfae68f60b5eb39634de1
BLAKE2b-256 e697ff21eb072f7203c6370702fb0071071f72f635e4ba381fd9e52579ec5d76

See more details on using hashes here.

Supported by

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