Skip to content

Instantly share code, notes, and snippets.

@tswann
Created October 19, 2017 14:18
Show Gist options
  • Save tswann/6557bf0725f6baaeadf92c5a04c34811 to your computer and use it in GitHub Desktop.
Save tswann/6557bf0725f6baaeadf92c5a04c34811 to your computer and use it in GitHub Desktop.
from functools import singledispatch
@singledispatch
def myfunction(obj):
print(‘Do something generic: {}’.format(obj))
@myfunction.register(int)
def _(num):
  print(‘Do something octal: {0:o}’.format(num))
@myfunction.register(float)
def _(num):
  print(‘Do something floaty: {0:.2f}’.format(num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment