معرفی شرکت ها


enum-switch-0.1.0


Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر

توضیحات

An Enum-based implementation of switch for Python.
ویژگی مقدار
سیستم عامل -
نام فایل enum-switch-0.1.0
نام enum-switch
نسخه کتابخانه 0.1.0
نگهدارنده []
ایمیل نگهدارنده []
نویسنده Roberto Alsina
ایمیل نویسنده roberto.alsina@gmail.com
آدرس صفحه اصلی https://github.com/ralsina/enum_switch
آدرس اینترنتی https://pypi.org/project/enum-switch/
مجوز MIT
# Enum-based Switch for Python This is an attempt at creating a way to do a reliable, not-bug-prone implementation, for Python, of a `switch` thing like other languages have. ## How it works Suppose you have an enum, like this: ``` class Color(Enum): RED = 1 GREEN = 2 BLUE = 3 ``` And you want to implement logic which branches based on a value which is of type `Color`. You can do it by subclassing the `Switch` class. The syntax should be obvious, but: * Inherit from Switch * Implement a method for each value of the Enum * If you are not implementing them all: add a `default` method. * If you leave any Enum value unaccounted for: it will raise an exception when you instantiate your class. Then: * Instantiate your class * Call it as a function passing it a value from the Enum * The respective method will be executed and its return value returned ``` from enum_switch import Switch class MySwitch(Switch): def RED(self): return "Apple" def GREEN(self): return "Kiwi" def BLUE(self): return "Sky" switch = MySwitch() print(switch(Color.RED)) Apple ``` And that's it. Some additional notes: * Passing it something that is not a value of the correct Enum type will raise ValueError * `default` is optional Hope someone finds it useful!


زبان مورد نیاز

مقدار نام
>=3.4 Python


نحوه نصب


نصب پکیج whl enum-switch-0.1.0:

    pip install enum-switch-0.1.0.whl


نصب پکیج tar.gz enum-switch-0.1.0:

    pip install enum-switch-0.1.0.tar.gz