Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

python - Auto-Loading a module on IPython startup

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i've found a solution to this one, in your IPython profile directory (by default - .ipythonprofile_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']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...