Created
February 28, 2013 02:23
-
-
Save mattrobenolt/5053674 to your computer and use it in GitHub Desktop.
David Cramer math
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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