我错过了一些非常基本的东西。
class C:
def __init__(self):
self.N = 100
pass
def f(self, param):
print 'C.f -- param'
for k in xrange(param):
for i in xrange(self.N):
for j in xrange(self.N):
a = float(i)/(1+float(j)) + float(i/self.N) ** float(j/self.N)
import cProfile
c = C()
cProfile.run('c.f(3)')
当我在 IPython 中运行上述代码时,我得到:
NameError: name 'c' is not defined
我错过了什么?
更新我的会话的确切粘贴在这里: http: //pastebin.com/f3e1b9946
更新我没有提到问题发生在 IPython 中,这(事实证明)是问题的根源