ugly_switch
An ugly pseudo solution for using switches in python.
Installation
pip install ugly_switch
Usage
from ugly_switch import switch
A Switch can be used once:
switch[
True, door_lock,
False, door_unlock
](not door_state)
# looks the door when it's state is False and vice versa
or can be stored to be used multiple times in the future:
s = switch[
'a', lambda: print('was a'),
'b', lambda: print('was b')
]
# some stuff
value = 'a'
s(value)
# OUT: "was a"
When the number of args in the switch is even, the pairs make up the switch as sets of cases and actions. actions must be callable methods or lambdas. If the number of args may be odd, the last item will be used as default, expecting it to be a callable.
With the example directly above, nothing will happen, if value
happens to be neither 'a' nor 'b'.
Below it has a default action.
value = 'c'
s = switch[
'a', lambda: print('was a'),
'b', lambda: print('was b'),
lambda: print('something else')
]
# some stuff
s(value)
# OUT: "something else"
Metadata
Release files for ugly-switch 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ugly_switch-0.1.2.tar.gz | 3.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ugly_switch-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / ugly_switch-0.1.2.tar.gz
| Download URL | ugly_switch-0.1.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d32515c37f9cb7892adaf914636c01c680b4083cbc12fcde7964011c9b269eb0
|
|
BLAKE2b-256 checksum How to use checksums |
cbb176a8cc79a060aa7b7eead45accdd6bba054e7b50a07be18a51fbe302a3f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Release files / ugly_switch-0.1.2-py3-none-any.whl
| Download URL | ugly_switch-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
957714b583eca042b1c05719245cf8e7a48a8d4858798ac8b02ba667d3759b6b
|
|
BLAKE2b-256 checksum How to use checksums |
aa055773f1c239f8e4d4646f9003ad31b819ac9e642620a67d3797b4cc8b3bce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Security for ugly-switch 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.