【问题标题】:Getting Ipython QtConsole's current config infomation in it's interactive shell在它的交互式 shell 中获取 Ipython QtConsole 当前配置信息
【发布时间】:2014-03-24 05:36:51
【问题描述】:

我看到how to change the configuration of ipython 临时或永久使用命令行参数或修改ipython_qtconsole_config.py。

我的问题是,我怎样才能像 ipython_qtconsole_config.py 那样获得当前配置:

c = get_config()
c.IPythonWidget.font_family = 'Consolas'

我可以import IPython,但不知道该怎么办...

【问题讨论】:

    标签: python configuration settings ipython


    【解决方案1】:

    您可以通过get_ipython().config访问它:

    get_ipython().config['IPythonWidget']['font_family']
    

    例子:

    In [1]: ip = get_ipython()
    
    In [2]: ip.config
    Out[2]: 
    {'IPKernelApp': {'connection_file': u'C:\\Users\\falsetru\\.ipython\\profile_default\\security\\kernel-7008.json',
      'interrupt': 960,
      'parent_appname': 'ipython-qtconsole',
      'parent_handle': 956},
     'IPythonWidget': {'font_family': u'Consolas'},
     'ProfileDir': {},
     'Session': {'key': u'4c0284b9-3a26-4989-b995-c930ab67bef5'}}
    
    In [3]: ip.config['IPythonWidget']['font_family']
    Out[3]: u'Consolas'
    

    【讨论】:

    • 非常感谢!!现在我想知道,您通常如何找到这样的答案?
    • @zhangxaochen, 1. 查找文档。 2.如果1失败,下载源代码+grep 3.如果2失败,另谋出路/放弃。 (如果找到答案,请确认答案有效。)
    • @zhangxaochen,我做了一些事情(对不起,我不记得我到底做了什么,一些grep,徘徊的IPython源代码树)....跟随类层次结构:TerminalInteractiveShell -> InteractiveShell -> SingletonConfigurable -> Configurable.
    • @zhangxaochen,发现Configurable对象集config属性通过。我在ipython shell 中尝试了get_ipython().config。有我设置的配置。我在ipython qtconsole --IPythonWidget.font_family=Consolas 做了同样的事情。就是这样。
    猜你喜欢
    • 2011-07-24
    • 2010-10-31
    • 2016-09-22
    • 1970-01-01
    • 2018-03-04
    • 2017-11-24
    • 2012-06-01
    • 2014-05-24
    • 1970-01-01
    相关资源
    最近更新 更多