2010-02-08 3 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

감사합니다 - 나는 버그 리포트를 제출합니다 – astrofrog

+0

@Morgoth 난 그냥했다 : https://bugs.launchpad.net/ipython/+bug/518982 – interjay

+0

아차, 당신이 버그를 제출해야한다고 보았다 report too – 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