Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Pyscripter中的函数调用时,日志记录未写入文件_Python_Logging_Pyscripter - Fatal编程技术网

Python 从Pyscripter中的函数调用时,日志记录未写入文件

Python 从Pyscripter中的函数调用时,日志记录未写入文件,python,logging,pyscripter,Python,Logging,Pyscripter,当前,如果我从python命令行运行以下代码,它会按预期写入filename指定的文件 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.

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

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中?

Pyscripter有一个“外部运行”选项(运行>外部运行(Alt+F9)),选择此选项可以使日志工作。

将Python引擎切换到内部。转到运行-->Pyton Engine-->Internal

您需要向我们展示一些代码,并通常向我们提供更多信息。该函数是在顶级脚本中还是在导入的模块中?您是否确实在函数中执行
导入日志记录
日志记录.basicConfig(…)
?(还有所有愚蠢的东西,比如:函数真的被调用了吗?)。我保证文件路径确实存在。是否存在名为
\\Stuff\folder
的有效可写网络共享?如果您只是将open(r'\\Stuff\folder.test.log',w')作为f:f.write('test')而不是使用
logging
,这是否有效?只想添加“External Run”方法,该方法通过菜单选项Run>External Run(Alt+F9)访问,日志信息直接指向输出选项卡,而不是Python解释器选项卡。