我已经卡在这里一个小时了。我已经将日志插入到我的tkinter gui中,但无法使其工作。然后我开始删除部分,直到我得到非常python文档中的简化示例,但它仍无法工作。此时我没有其他可以删除的部分了。
代码如下:
import logging
LOG_FILENAME = r'logging_example.out'
logging.basicConfig(filename=LOG_FILENAME ,level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
f = open(LOG_FILENAME, 'rt')
try:
body = f.read()
finally:
f.close()
print('FILE:')
print (body)
警告信息将被打印到标准输出,但文件不会生成。我正在运行Python 3.4 x64版本,使用Windows 7操作系统。这是Anaconda发行版,因此在Spyder中的IPython中运行。
我猜这应该可以正常工作。