2

I've seen how to change the configuration of ipython either temporarily or permanently using commandline args or modifying ipython_qtconsole_config.py.

My question is, how can I get the current configuration like the ipython_qtconsole_config.py does:

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

I can import IPython, but don't know what to do then...

Community
  • 1
  • 1
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108

1 Answers1

2

You can access it through get_ipython().config:

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

Example:

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'
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • thx a lot!! now I'm wondering, how do you usually find such an answer? – zhangxaochen Feb 22 '14 at 16:02
  • 1
    @zhangxaochen, 1. Find documentation. 2. If 1 fail, Download the source code + `grep` 3. If 2 fail, find other way / give up. (If find answer(s), confirm that the answer is valid.) – falsetru Feb 22 '14 at 16:05
  • @zhangxaochen, I did something (Sorry, I don't remember what I did exactly, some `grep`, wandering IPython source tree) .... followed class hierachy: `TerminalInteractiveShell` -> `InteractiveShell` -> `SingletonConfigurable` -> `Configurable`. – falsetru Feb 22 '14 at 17:13
  • @zhangxaochen, And found that the `Configurable` object set `config` attribute passed. I tried `get_ipython().config` in `ipython` shell. There was configuration I set up. I did same thing in `ipython qtconsole --IPythonWidget.font_family=Consolas`. That's it. – falsetru Feb 22 '14 at 17:16