문제

나는 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를 잘못 사용하고 있습니까?

도움이 되었습니까?

해결책

Ipython에는 버그가있는 것 같습니다. demo.py에서 LineDemo.reload, 말하는 선 :

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

말해야합니다 :

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

현재 파일의 모든 줄 대신 첫 번째 줄에서 모든 글자를 실행하려고합니다.

편집하다: 버그가보고되었습니다.

다른 팁

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. ********************
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top