使用structlog隐藏控制台



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

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

这里有一个简单的测试来揭示这个问题。

# 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

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

最新更新