Domanda
Sto cercando di utilizzare l'IPython demo modalità . Ho creato un file chiamato test.py
contenente:
print 1
print 2
print 3
e poi ha lanciato IPython e ha fatto il seguente:
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
Ciò che è probabile che causare questo errore? Sto usando LineDemo in modo errato?
Soluzione
Sembra che ci sia un bug in IPython. In demo.py nel LineDemo.reload
, la riga che dice:
src_b = [l for l in self.fobj.readline() if l.strip()]
dovrebbe dire:
src_b = [l for l in self.fobj.readlines() if l.strip()]
Al momento si sta cercando di eseguire tutte le lettere nella prima linea, invece di tutte le righe nel file.
Modifica:. Bug segnalati
Altri suggerimenti
Funziona bene in IPython 0.9.1
Quale versione avete?
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. ********************
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow