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.

Source Distribution

try_match-0.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

try_match-0.2.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file try_match-0.2.0.tar.gz.

File metadata

  • Download URL: try_match-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/4.4.0-18362-Microsoft

File hashes

Hashes for try_match-0.2.0.tar.gz
Algorithm Hash digest
SHA256 96c9fdce8e34b4669c5f12f4e200f87cad574ef398cbcef33b545a8ada089010
MD5 66e1c9abef7272674e04c6286f99ccad
BLAKE2b-256 27b2a2c6bb4b5c736208cafd70c2621073a6e1f142d4c8d55904dd033150b2dc

See more details on using hashes here.

File details

Details for the file try_match-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: try_match-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/4.4.0-18362-Microsoft

File hashes

Hashes for try_match-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 de8db9cb462117bcce1fef7ae9f123fb661ae24b47b9b6af936a72658bb53b23
MD5 18071343bde5ebeac49a06f01b722efd
BLAKE2b-256 464228b8ac16f21f3f3f277618bba78c69df6f26c1fc69c23f9369cecbb23b30

See more details on using hashes here.

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