Skip to main content

No project description provided

Project description

I have noticed that switch/case statements are coming to Python, so I thought it would be amusing to release the 101002938662893028482039th "Missing switch/case package" to this platform.

import switchem

MONKEY = 1
ELEPHANT = 2
GIRAFFE = 3
HORSE = 4
SQUIRREL = 5
SQUID = 6
COW = 7
SARCASTIC_FRINGEHEAD = 8

with switchem(HORSE) as case:
    if case(MONKEY):
        print("It is a monkey")
        raise case
    
    if case(ELEPHANT, GIRAFFE, HORSE):
        print("It is not a monkey for sure")
    
    if case(SQUIRREL):
        print("It could be a squirrel")
        raise case
    
    print("It is definitely not a monkey, elephant, giraffe, horse, or squirrel")

This has the fall-through behaviour (fall-through will activate as soon as the correct value is checked). To "break", raise the case object within the context.

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

switchem-1.0.0.tar.gz (1.9 kB view details)

Uploaded Source

File details

Details for the file switchem-1.0.0.tar.gz.

File metadata

  • Download URL: switchem-1.0.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.4

File hashes

Hashes for switchem-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5aa43800f0022880be0505eee94810d51bee57993e2089e194016398175cb763
MD5 b39dc80d956bf46ad78334f42bfb041e
BLAKE2b-256 ca7d4eafc2a87cd1d9760b67fb59794c2ef8d606bddeef28110c43a8bdce06a1

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