Python:导入函数的模拟

Python:导入函数的模拟,python,import,python-import,Python,Import,Python Import,假设我有一个大程序,有许多对其他库的调用,我想通过缓慢地更改每个函数来了解它是如何工作的。 为了论证:我有: import numpy print numpy.sqrt(2) ...(many other calls to numpy.sqrt) 我想创建我的内部函数sqrt,而不是导入numpy。我看到这样的情况: #import numpy def numpy: def sqrt(x): return x print numpy.sqrt(2) #now pr

假设我有一个大程序,有许多对其他库的调用,我想通过缓慢地更改每个函数来了解它是如何工作的。 为了论证:我有:

import numpy
print numpy.sqrt(2)
...(many other calls to numpy.sqrt)
我想创建我的内部函数sqrt,而不是导入numpy。我看到这样的情况:

#import numpy

def numpy:
    def sqrt(x):
        return x


print numpy.sqrt(2) #now program calls my own numpy.sqrt function

怎么做?

这不完全是我需要的,但我会用这种方式试试。
import numpy

def sqrt(x):
    return x

numpy.sqrt = sqrt