【问题标题】:Equivalent to C++'s std::clog in Python?相当于 Python 中 C++ 的 std::clog 吗?
【发布时间】:2017-07-18 06:55:04
【问题描述】:

当主程序渲染图像时,这段 C++ 代码将在终端上显示“加载文本”。我知道它这样做是因为 std::clog。我一直在寻找,我认为 subprocess 模块可以帮助我在 Python 上重现它,但我完全不知道如何使用它。你会如何用 Python 编写代码?

   std::stringstream progress_stream;
   progress_stream << "\r  progress .........................: "
                    << std::fixed << std::setw( 6 )
                    << std::setprecision( 2 )
                    << 100.0 * y / ( buffer_.v_resolution_ - 1 )
                    << "%";

    std::clog << progress_stream.str();

【问题讨论】:

  • 使用print并选择stderr有什么问题吗?
  • @chris 这是我需要的,但我不知道。它按预期工作!

标签: python c++ clog


【解决方案1】:

最接近的等价物是print(a_string_variable, file=sys.stderr)

【讨论】:

  • 我会尝试并提供反馈!谢谢你!
  • 更新:这正是我想要的,非常感谢!
猜你喜欢
  • 1970-01-01
  • 2011-02-07
  • 2011-05-16
  • 2020-09-28
  • 2011-06-25
  • 2010-12-21
  • 2011-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多