0

structlog 可以与pythonw一起使用以仅登录文件吗?

使用 pythonw 运行 python 代码时导入 structlog 失败,因为sys.stdoutis None. 调用时
在文件中引发错误。structlog/_config.pysys.stdout.isatty()

这是一个揭示问题的简单测试。

# python try_import_structlog.pyw --> success
# pythonw try_import_structlog.pyw --> fail

with open("result.txt", "a") as file:
    try:
        import structlog
    except Exception as error:
        file.write(f"import failed: {error}")
    else:
        file.write("import succeeded")

https://github.com/hynek/structlog/issues/313

4

1 回答 1

0

这是 structlog 中的一个错误,将在下一个版本中修复!我想它可能会在这个周末发布。

于 2021-04-30T13:00:44.173 回答