1

我正在尝试在python(或ipython)中找到idl's journal的等效功能。我知道 ipython 有 %logstart 函数,但它只记录 ipython 中的输入/输出,所以如果我运行我的脚本并要求我输入值,这些不会进入日志。当我运行 EELTnoM6.py 脚本时,这里是我的终端:

In [11]: run EELTnoM6

################################################################
##             STOKES vector after the system                 ##
################################################################ 

== Demodulation matrix ==
Automatic:                A
ZIMPOL/EELT:              Z
EELT IF                   Eif
Custom                    C
Demodulation matrix?: C
Efficiency of the detector?: 1.
Demodulation matrix? (e.g. [ [1.,0.],[0.,1.] ]): [[1/6.,1/6.,1/6.,1/6.,1/6.,1/6.],     [0.5,-0.5,0.,0.,0.,0.],[0.,0.,-0.5,0.5,0.,0.],[0.,0.,0.,0.,-0.5,0.5]]
ModelStokesMeasurement time =  65.6509261131
Simulation time =  151.731481075

这是我在日志中得到的:

# IPython log file
%logstart -o -r EELTnoM6_log rotate
ls
%logstop
run EELTnoM6
%logoff

我想将脚本询问时给出的输入存储在日志中,即

Demodulation matrix?: C 
Efficiency of the detector?: 1.
Demodulation matrix? (e.g. [ [1.,0.],[0.,1.] ]): [[1/6.,1/6.,1/6.,1/6.,1/6.,1/6.],[0.5,-0.5,0.,0.,0.,0.],[0.,0.,-0.5,0.5,0.,0.],[0.,0.,0.,0.,-0.5,0.5]]

所以 C, 1. 和矩阵能够以相同的值再次运行它。这在 IDl 中非常容易,所以当我找不到 ipython 的相同内容时,我感到非常惊讶......

4

1 回答 1

0

我认为您只想使用日志记录功能。它非常棒,并且可以很好地处理多线程。

import logging

log_file = 'journal.log' # Specify path to your log file

log_format = '[%(asctime)s] %(levelname)s: %(message)s'  # How the output is displayed
log_date_fmt = '%m/%d/%Y %I:%M:%S %p'  # How the asctime is displayed

logging.basicConfig(filename=log_file, level='DEBUG', filemode='w', format=log_format, datefmt=log_date_fmt)  # Fire up the logger
logging.info('Logger initialized')  # There are DEBUG, INFO, WARNING, ERROR levels

def journal(msg):
    ans = raw_input(msg)  # Get your user input
    logging.debug(msg + ans)  # Choosing to put it as DEBUG category
    return ans

ans = journal('Demodulation matrix?: ')  # From your example

给出输出(包含在./journal.log

[09/17/2014 04:11:49 PM] 信息:记录器已初始化

[09/17/2014 04:11:51PM] 调试:解调矩阵?:C

于 2014-09-17T20:11:10.403 回答