本文介绍了从Pyscripter中的函数调用时记录未写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,如果我从python命令行运行以下代码,它会按预期写入filename指定的文件.

Currently if I run the following code from the python command line it writes to the file specified by filename as expected.

import logging
def test():
    logging.basicConfig(format='%(asctime)s %(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        filename=r'C:\Users\theo\Documents\myLog.txt')
    logging.warning('Example logged message.')
test()

但是,当我将代码复制到我的一个函数中并使用Pyscripter运行该函数时,它似乎没有写入文件.如何使日志记录出现在Pyscripter中?

But when I copy the code into one of my functions and run the function with Pyscripter, it does not seem to write the file.How can I get logging to appear in Pyscripter?

推荐答案

Pyscripter具有外部运行"选项(运行">外部运行"(Alt + F9)),选择此项可使日志记录正常工作.

Pyscripter has an 'External Run' option ( Run > External Run (Alt + F9)), choosing this made the logging work.

这篇关于从Pyscripter中的函数调用时记录未写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 12:21