2010-02-08 63 views
2

我試圖使用IPython demo模式。我創建了一個名爲test.py文件,其中包含:IPython演示模式

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?

回答

2

IPython似乎存在一個錯誤。在LineDemo.reload demo.py,行,說:

src_b   = [l for l in self.fobj.readline() if l.strip()] 

應該說:

src_b   = [l for l in self.fobj.readlines() if l.strip()] 

目前,它正試圖在第一線執行所有的字母,而不是文件中的所有行。

編輯:Bug reported

+0

謝謝 - 我會提交一個bug報告 – astrofrog

+0

@Morgoth我只是做:https://bugs.launchpad.net/ipython/+bug/518982 – interjay

+0

哎呀,剛纔看到你必須提交一個bug報告太 – astrofrog

0

它可以在IPython 0.9.1中正常工作
你有哪個版本?

In [1]: from IPython.demo import LineDemo 

In [2]: d = LineDemo('test.py') 

In [3]: d() 
********************* <test.py> block # 0 (2 remaining) ********************* 
print 1 
********************************** output: ********************************** 
1 

In [4]: d() 
********************* <test.py> block # 1 (1 remaining) ********************* 
print 2 
********************************** output: ********************************** 
2 

In [5]: d() 
********************* <test.py> block # 2 (0 remaining) ********************* 
print 3 
********************************** output: ********************************** 
3 

******************************** END OF DEMO ******************************** 
******************** Use reset() if you want to rerun it. ******************** 
+0

錯誤來自於此更改:http://bazaar.launchpad.net/~ipython-dev/ipython/trunk/revision/1160.3.1,所以它是僅在0.10。 – interjay

+0

我正在使用0.10 - 該錯誤必須在該版本中引入 – astrofrog