Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
David Cramer math
"""
cramermath
~~~~~~~~~~
Usage:
>>> import cramermath
>>> cramermath.log(10)
0.014728067495500818
"""
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
You can’t perform that action at this time.