Skip to main content

Switch Case实现的Python库

项目描述

PyPI 版本 PyPI 版本 PyPI 版本

PyPI 安装 PyPI 版本 PyPI 下载

  • BigQuery | Google cloud <==>

下载 下载 下载

Switch Case( SmartSwitchCase)实现的Python库

SmartSwitchCase是一个用于使用 switch case 语句的简单库。

要求

必须安装Python >= 2.7 。

Install

smartswitchcase在 PyPI 上发布,所以你只需要:

$ pip install smartswitchcase

要升级到最新版本:

$ pip install --upgrade smartswitchcase

用法

基本用法

from smartswitchcase import SmartSwitchCase,Case

var = 2


def first():
    print("I'm ... 1")


def two():
    print("I'm ... 2")

# Initialisation
swc = SmartSwitchCase(var)
# Add case
swc.case(Case(1, first))
swc.case(Case(2, two))
# Add default statement
swc.default(lambda: "I'm ... Default")
# Run
swc.exc()

# >>> CONSOLE : I'm ... 2 <<<

提前使用

from smartswitchcase import SmartSwitchCase, Case
import random

obj = random.randint(1, 11)


def first():
    return "I'm ... 1"


def two():
    return "I'm ... 2"


# Initialisation
swc = SmartSwitchCase(obj)
# Add case
swc.case(Case(1, first))
swc.case(Case(2, two))
swc.case(Case(3, lambda: "I'm ... 3"))
swc.case(Case(4, lambda: "I'm ... 4"))
swc.case(Case(5, lambda: "I'm ... 5"))
swc.case(Case(6, lambda: "I'm ... 6"))
swc.case(Case(7, lambda: obj * 7))
swc.case(Case(8, lambda: 888))
swc.case(Case(9, lambda: 999))
# Add default statement
swc.default(lambda: "I'm ... Default")
# Run
swc.exc()
# If you statement return a result you can get her after execution
result = swc.result()
# Show the result
print(result)

文档

  • SmartSwitchCase:取一个参数(你要测试的语句值)
  • Case取两个参数(value, func):
    • 案件价值
    • 如果 case 匹配,func 是执行函数

项目结构:

  • smartqwitchcase- 一个包的源代码
  • examples- 工作示例

贡献

  1. 如果不确定,请打开一个问题进行讨论
  2. 创建一个分叉
  3. 做出改变
  4. 发出拉取请求
  5. 快乐的贡献!

支持或咖啡:)

截屏

作者:科菲·乔尔·奥尼波

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

smartswitchcase-1.0.tar.gz (3.3 kB 查看哈希

已上传 source