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))
Metadata
Release files for python-switch 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_switch-1.0.tar.gz | 3.2 kB | Details |
Release files / python_switch-1.0.tar.gz
| Download URL | python_switch-1.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a93162710407c082060a2a4464a8d8c722f5f9153887b5f9ec1bab443b36df94
|
|
BLAKE2b-256 checksum How to use checksums |
9bf3cd49edd211cceef4560936972b7eba9b1d3d7657e7d84d20fe4c92e807cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|