Skip to content

Instantly share code, notes, and snippets.

@mattrobenolt
Created February 28, 2013 02:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattrobenolt/5053674 to your computer and use it in GitHub Desktop.
Save mattrobenolt/5053674 to your computer and use it in GitHub Desktop.
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