ipython 的以 开头的配置文件在哪里c = get_config()
执行?我问是因为我想了解 ipython 中的操作顺序,例如为什么某些命令如果包含为c.InteractiveShellApp.exec_lines
.
这与我的另一个问题Log IPython output? ,因为我想访问一个logger
属性,但我无法弄清楚如何在配置文件中访问它,并且exec_lines
运行时,记录器已经启动(为时已晚)。
编辑:我已经接受了基于在ipython0.12+
. 这是我对该解决方案的实现:
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')