Auto-Loading a module on IPython startup

半世苍凉 提交于 2019-11-26 23:16:01

问题


I'm trying to to auto load the division module from __future__ on startup, i've currently got a simple script in the IPython startup libray with the line:

from __future__ import division

which works fine when run directly from the shell, however, the module does not appear to load when the line is run from the script, i made sure that the startup script is loaded by adding some arbitrary variable assignments to it:

from __future__import division
x=1
y=2

and the variables were preassigned when IPython was launched (as expected).

I've tried looking at some solutions here and here but got nowhere, any help would be appreciated, thanks


回答1:


i've found a solution to this one, in your IPython profile directory (by default - .ipython\profile_default), edit the file ipython_config.py (create it with ipython profile create if it does not exist) with the following lines:

# loads the root config object
c=get_config()

# executes the line in brackets on program launch
c.InteractiveShellApp.exec_lines = ['from __future__ import division']


来源:https://stackoverflow.com/questions/20835977/auto-loading-a-module-on-ipython-startup

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