ipython文件每次打开重新运行吗_ipython的配置文件在何处/如何/在什么情况下执行?...

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.

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).

EDIT: 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

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')

解决方案

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值