4

標準のPythonインタラクティブシェルでは、Ctrl+を押しDてstdinを閉じることができ、出力が表示されます。

$ python
Python 2.7.2 (default, Mar  7 2012, 21:18:58) 
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> for f in range(5):
...     print f     (I press Enter here)
...                 (I press Ctrl+D here) 
0
1
2
3
4
>>> 

しかし、IPythonとbpythonでは、Ctrl+Dが機能しないEnterため、結果を得るには2回押す必要があります。

IPython:

In [1]: for f in range(5):
   ...:     print f     (I press Enter here)
   ...:                 (I press Enter here)
   ...:                 (I press Enter here)
0
1
2
3
4

bpython:

>>> for f in range(5):
...     print f     (I press Enter here)
...                 (I press Enter here)
...                 (I press Enter here)
0
1
2
3
4

私が使用しているバージョン:

[I] dev-python/ipython
     Available versions:  0.10 0.10.1 0.10.2 ~0.12-r1 {doc emacs examples gnuplot matplotlib mongodb notebook qt4 readline (+)smp sqlite test wxwidgets}
     Installed versions:  0.10.2(03:54:09 PM 08/12/2011)(examples readline -doc -emacs -gnuplot -smp -test -wxwidgets)
     Homepage:            http://ipython.org/
     Description:         Advanced interactive shell for Python

[I] dev-python/bpython
     Available versions:  0.9.7.1 0.10.1 {gtk urwid}
     Installed versions:  0.10.1(10:34:17 AM 03/14/2012)(gtk -urwid)
     Homepage:            http://www.bpython-interpreter.org/ https://bitbucket.org/bobf/bpython/ http://pypi.python.org/pypi/bpython
     Description:         Syntax highlighting and autocompletion for the Python interpreter
4

2 に答える 2

0

IPython をバージョン 0.12-r1 にアップグレードすることで、問題の半分を解決しました。

[I] dev-python/ipython
     Available versions:  0.10 0.10.1 0.10.2 (~)0.12-r1 {doc emacs examples gnuplot matplotlib mongodb notebook qt4 readline (+)smp sqlite test wxwidgets}
     Installed versions:  0.12-r1(11:47:58 AM 03/16/2012)(examples qt4 readline smp -doc -emacs -matplotlib -mongodb -notebook -sqlite -test -wxwidgets)
     Homepage:            http://ipython.org/
     Description:         Advanced interactive shell for Python

2 回押すだけでよいことに注意して...:くださいEnter。1 回目は新しい行を作成し、2 回目は標準入力を閉じて結果を表示します。

$ ipython
Python 2.7.2 (default, Mar  7 2012, 21:18:58) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: for i in range(2):
   ...:     for j in range(2):
   ...:         print i*j
   ...:         
0
0
0
1

bpython については、出力を表示する前にインデントのない行に移動する必要があります。テスト目的で、ネストされたforループを2 つ使用する場合は、 Enter4 回押す必要があります。

>>> for i in range(2):
...     for j in range(2):
...         print i*j
...         
...     
... 
0
0
0
1
于 2012-03-16T05:12:10.483 に答える
-1

キーを 2 回押すだけEnterで、標準の Python インタラクティブ シェルと IPython で同じ結果と効果が得られます。

于 2012-03-15T13:02:49.297 に答える