原因是我有时会使用shell/interpreter作为计算器,并且几乎总是想要真正的除法,而且我已经厌倦了总是输入它!
打开~/.ipython/profile_default/ipython_config.py并搜索c.InteractiveShellApp.exec_lines.我正在使用IPython 1.2,它位于文件的顶部.设置如下:
c.InteractiveShellApp.exec_lines = ["from __future__ import division", "import something", "another statement"]
Run Code Online (Sandbox Code Playgroud)
每个字符串都是你想要在IPython启动时执行的一行Python代码.保存文件,重启IPython,你应该全部设置好.
如果此文件不存在,请通过运行创建配置文件
ipython profile create
Run Code Online (Sandbox Code Playgroud)
在命令行,它将自动为您生成.