Python Switch Like JavaScript Switch Statement
Project description
Python Switch Like JavaScript Switch Statement
Installing
Install and update using pip:
pip install python-switch
A Simple Examples
from python_switch import Switch
s = Switch({"d":lambda x:f"returns {x} (d)","default":lambda x: f"returns {x} (default)"})
print(s.get("d")(1))
Adding a case later.
from python_switch import Switch
s = Switch({"default":lambda x: f"returns {x} (default)"})
s.addCase("d",lambda x:f"returns {x} (d)")
print(s.get("d")(1))
Adding cases with the decorator.
from python_switch import Switch
s = Switch({"default":lambda x: f"returns {x} (default)"})
@s.case()
def d(x):
return f"returns {x} (d)"
print(s.get("d")(1))
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
python_switch-1.0.tar.gz
(3.2 kB
view details)
File details
Details for the file python_switch-1.0.tar.gz
.
File metadata
- Download URL: python_switch-1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a93162710407c082060a2a4464a8d8c722f5f9153887b5f9ec1bab443b36df94 |
|
MD5 | 0a61ac37b81d8315114ecc2d66c7a2fb |
|
BLAKE2b-256 | 9bf3cd49edd211cceef4560936972b7eba9b1d3d7657e7d84d20fe4c92e807cc |