【问题标题】:Auto-Loading a module on IPython startup在 IPython 启动时自动加载模块
【发布时间】:2013-12-30 08:32:38
【问题描述】:

我正在尝试在启动时从__future__ 自动加载division 模块, 我目前在 IPython 启动库中有一个简单的脚本:

from __future__ import division

直接从 shell 运行时效果很好, 但是,从脚本运行该行时,该模块似乎没有加载, 我通过向其添加一些任意变量分配来确保加载启动脚本:

from __future__import division
x=1
y=2

并且在 IPython 启动时预先分配了变量(如预期的那样)。

我已经尝试查看一些解决方案 herehere 但无济于事, 任何帮助,将不胜感激, 谢谢

【问题讨论】:

  • 请从问题中删除解决方案并将其作为答案发布在下面并接受它。
  • 请注意,问题在于将__future__ 调用放入脚本中,您会激活该脚本中 的功能,而不是在解释器中的“全局级别”。
  • 那会有什么后果?

标签: python python-2.7 module ipython startup


【解决方案1】:

我找到了一个解决方案,在您的 IPython 配置文件目录中(默认情况下 - .ipython\profile_default),使用以下行编辑文件 ipython_config.py(如果它不存在,则使用 ipython profile create 创建它) :

# loads the root config object
c=get_config()

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

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 2016-05-04
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 2013-05-23
    • 2023-03-20
    • 2019-09-18
    • 2017-12-10
    相关资源
    最近更新 更多