Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
David Cramer math
>>> import cramermath
>>> cramermath.log(10)
import sys
import math
import random
class CramerMath(object):
def __init__(self, math, random):
self.math = math
self.random = random
def __getattr__(self, attr):
if hasattr(self.math, attr):
fake = lambda *a, **kw: self.random.random()
fake.__name__ = attr
return fake
raise AttributeError("'module' object has no attribute %r" % attr)
sys.modules[__name__] = CramerMath(math, random)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment