Skip to main content

Pattern matching

Project description

try_match

Pattern matching

It supports Python 2.7 and 3+

Installation

Using pip to install

pip install try-match

Usage

from try_match import Case, match, DefaultCase

### match value
try:
    match(1)
except Case(2):
    raise
except Case(1):
    print(1)
   
# => 1


### match class
try:
    match(1)
except Case(str):
    raise
except Case(int):
    print('int')
    
# => 'int'


### match range
try:
    match(10)
except Case(range(1, 5)):
    raise
except Case(range(9, 20)):
    print(range(9, 20))
    
# => range(9, 20)


### match lambda
try:
    match(2)
except Case(lambda x > 5):
    raise
except Case(lambda x < 5):
     print("x < 5")
     
# => "x < 5"


### default case
try:
    match(1)
except Case(2):
    raise
except Case(3):
    raise
except DefaultCase:
    print("default")
    
# => "default"

✨🍰✨ enjoy it

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for try-match, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size try_match-0.2.0-py2.py3-none-any.whl (6.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size try_match-0.2.0.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page