pythonc++clog

Equivalent to C++'s std::clog in Python?


This piece of C++ code will display a "loading text" on the Terminal as the main program renders an image. I know that it does it because of the std::clog. I've been searching, and I think that the subprocess module can help me with reproducing this on Python, but I have absolutely no idea on how to use it. How would you code this in 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();

Solution

  • The closest equivalent is print(a_string_variable, file=sys.stderr).