Skip to content

Instantly share code, notes, and snippets.

@elidchan
elidchan / switch.py
Last active May 14, 2020 19:32
Python switch statement
"""
Python switch statement
Usage:
```
from datetime import datetime
# import switch and case (below)
@elidchan
elidchan / context.py
Last active May 2, 2019 16:01
FlexContext, a context manager for context variables
from contextlib import suppress
from contextvars import ContextVar
FLEX_CONTEXT = ContextVar('flex_context', default={})
class ContextManagerReentryError(Exception):
pass
class FlexContext:
@elidchan
elidchan / verbiage.py
Created January 19, 2019 17:30
Utilities for indefinite article and plurality
import ast
import contextlib
import json
import os
import string
from collections import OrderedDict
from enum import Enum
from numbers import Number
from string import Template