Python, string format, newline (C ++ - std :: endl)

I format the string (when overloading the str statement), and I do not want to use the raw \ n or \ r \ n tags. Have a python cross platform id like std :: endl in c ++?

I am trying to do this but have not found an answer.

+4
source share
3 answers

How about using os.linesep ? It contains the appropriate line separator for your OS:

 >>> import os >>> os.linesep '\n' >>> print "line one" + os.linesep + "line two" line one line two 
+14
source

No. Use \n . And in C ++, std::endl is nothing more than "\n" << std::flush , and it is no more cross-platform, whatever that means. It is only slower, as it forces to rinse.

+7
source

There is nothing wrong with using \n - why don't you want to use it? A cross-platform problem only makes sense when writing to files, and a file object will take care of this for you.

+6
source

Source: https://habr.com/ru/post/1383866/


All Articles