IPython and REPL behave differently when displaying data without the print function

*爱你&永不变心* 提交于 2019-12-01 06:11:10

For how it works, IPython compiles loops in 'exec' mode instead of 'single', so sys.displayhook is not triggered for expression statements inside a loop. The regular interactive interpreter executes anything you enter in 'single' mode. 'single' mode is the mode where expression statements trigger sys.displayhook.

For why IPython does this, the regular Python behavior is more annoying than useful. You rarely want to auto-print the values of expression statements in a loop; more frequently, it'll happen by accident and scroll things you're interested in off the screen.

IPython tries to provide more useful behavior. It's much more intuitive to explicitly print the things you want printed than to explicitly suppress the things you don't want printed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!