ipython的配置文件在何处/如何/在什么情况下执行? [英] Where / how / in what context is ipython's configuration file executed?

查看:124
本文介绍了ipython的配置文件在何处/如何/在什么情况下执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ipython的配置文件在哪里,以 c = get_config()开头执行?我问,因为我想了解在ipython中做了什么顺序,例如如果包含为 c.InteractiveShellApp.exec_lines ,某些命令将无效。

Where is ipython's configuration file, which starts with c = get_config(), executed? I'm asking because I want to understand what order things are done in ipython, e.g. why certain commands will not work if included as c.InteractiveShellApp.exec_lines.

这与我的另一个问题有关, Log IPython输出?,因为我想访问 logger 属性,但我无法弄清楚如何在配置文件中访问它,并且时间<$运行c $ c> exec_lines ,记录器已经启动(为时已晚)。

This is related to my other question, Log IPython output?, because I want access to a logger attribute, but I can't figure out how to access it in the configuration file, and by the time exec_lines are run, the logger has already started (it's too late).

编辑:我已经接受了基于在 ipython0.12 + 中使用启动文件的解决方案。以下是我对该解决方案的实现:

I've accepted a solution based on using a startup file in ipython0.12+. Here is my implementation of that solution:

from time import strftime
import os.path

ip = get_ipython()

#ldir = ip.profile_dir.log_dir 
ldir = os.getcwd()
fname = 'ipython_log_' + strftime('%Y-%m-%d') + ".py"
filename = os.path.join(ldir, fname)
notnew = os.path.exists(filename)


try:
  ip.magic('logstart -o %s append' % filename)
  if notnew:
      ip.logger.log_write( u"########################################################\n" ) 
  else:
      ip.logger.log_write( u"#!/usr/bin/env python\n" )
      ip.logger.log_write( u"# " + fname + "\n" )
      ip.logger.log_write( u"# IPython automatic logging file\n" )
  ip.logger.log_write( u"# " + '# Started Logging At: '+ strftime('%Y-%m-%d %H:%M:%S\n') ) 
  ip.logger.log_write( u"########################################################\n" ) 
  print " Logging to "+filename
except RuntimeError:
    print " Already logging to "+ip.logger.logfname

建议的解决方案链接只有两个细微差别:
1.将日志保存到 cwd 而不是一些日志目录(尽管我更多...)
2. ip.magic_logstart 似乎不存在,而应该使用 ip.magic( 'logstart')

There are only two subtle differences from the proposed solution linked: 1. saves log to cwd instead of some log directory (though I like that more...) 2. ip.magic_logstart doesn't seem to exist, instead one should use ip.magic('logstart')

推荐答案

配置系统设置一个包含<$ c $的特殊命名空间c> get_config() function,运行配置文件,并收集值以在创建对象时将它们应用于对象。参考您之前的问题,它看起来不像记录输出的配置值。您可能希望在配置后开始自己记录,此时您可以更精确地控制它。请参阅此示例自动开始记录。

The config system sets up a special namespace containing the get_config() function, runs the config file, and collects the values to apply them to the objects as they're created. Referring to your previous question, it doesn't look like there's a configuration value for logging output. You may want to start logging yourself after config, when you can control it more precisely. See this example of starting logging automatically.

你的另一个问题提到你在一个系统上限制为0.10.2:它有一个完全不同的配置系统,甚至不会查看同一个文件。

Your other question mentions that you're limited to 0.10.2 on one system: that has a completely different config system that won't even look at the same file.

这篇关于ipython的配置文件在何处/如何/在什么情况下执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆