Skip to main content

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

This version

1.0

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 hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page