我正在尝试使用 IPython演示模式。我创建了一个名为test.py
包含的文件:
print 1
print 2
print 3
然后启动 IPython 并执行以下操作:
In [1]: from IPython.demo import LineDemo
In [2]: d = LineDemo('test.py')
In [3]: d()
********************* <test.py> block # 0 (5 remaining) *********************
p
********************************** output: **********************************
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/Users/tom/Library/Python/2.6/site-packages/ipython-0.10-py2.6.egg/IPython/demo.pyc in runlines(self, source)
400 """Execute a string with one or more lines of code"""
401
--> 402 exec source in self.user_ns
403
404 def __call__(self,index=None):
/Users/tom/tmp/<string> in <module>()
----> 1
2
3
4
5
NameError: name 'p' is not defined
什么可能导致此错误?我是否错误地使用了 LineDemo?