Skip to main content

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)

Source distribution for python-switch 1.0
File Size Uploaded Provenance Actions
python_switch-1.0.tar.gz 3.2 kB Without provenance Details for python_switch-1.0.tar.gz

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

Security for python-switch 1.0

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.

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page