[GRASS-dev] usage of os.linesep (was: Re: [GRASS-SVN] r68240 - grass/trunk/scripts/v.report_

Glynn Clements glynn at gclements.plus.com
Thu Apr 14 03:57:58 PDT 2016


> It seems to me that one of these is need and simple os.linesep is not
> enough. I'm never sure how Python solves this for splitlines() and others.

str.splitlines() treats any of '\n', '\r' and '\r\n' as a separator,
independent of platform.

The same approach is used if a file is opened with universal newlines
('U' in the mode string).

> I was quite struggling with it in the gunittest where sample data and code
> usually have \n but on Windows you get \r\n in the created data. Now I'm
> usually replacing \r\n everywhere and doing comparisons afterwards but
> that's not really applicable for the normal code.

Unless 'b' is added to the mode, on Windows '\n' will be converted to '\r\n' on
output and '\r\n' to '\n' on input.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list