simulatino / trimtrailingwhitespaces

Python script that detects textfiles and then removes trailing white spaces and more.
The Unlicense
11 stars 2 forks source link

EOL on Windows #27

Closed thorade closed 9 years ago

thorade commented 9 years ago

I just started to use ttws 0.6.0 on Windows 7 64 bit German with Python 3.4 ;-)

As discussed in #9 there is an option to enforce the line ending stlye. All my files have CRLF. If I run ttws --eol=CRLF TestDicrecoty everything is fine, but if I use ttws TestDirectory without specifying the eol option explicitly, ttws will convert everything to LF, even though the help text correctly states that my system uses \r\n aka CRLF. For now, I can perfectly live with explicitly specifying the EOL format, so this issue has vey low priority.

dietmarw commented 9 years ago

Also part of v0.6.1 now.

thorade commented 9 years ago

On my machine ttws v0.6.1 adds a CR to every trimmed line instead of CRLF. Can I print the value of os.linesep in IDLE?

dietmarw commented 9 years ago

On your machine could you do:

$ python3
Python 3.4.2 (default, Oct  8 2014, 13:08:17) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print(repr(os.linesep))
'\n'
thorade commented 9 years ago

That command returns \r\n (as also reported by ttws --help)

dietmarw commented 9 years ago

Are you sure you get CR instead of CRLF then?

thorade commented 9 years ago

eol_cr

dietmarw commented 9 years ago

OK I'll need to look into this. Funny that the line endings are different.

dietmarw commented 9 years ago

Just to let you know that I could reproduce this. Strange that it ONLY happens for CRLF, CR and LF work fine. Windows causing trouble again.

thorade commented 9 years ago

Thanks for confirming. I'll just use ttws --eol=CRLF for now, so no need to hurry.

dietmarw commented 9 years ago

Well that's the thing the CRLF option does not properly work.

thorade commented 9 years ago

Oh, now I see. It worked before the changes, I just had to enforce --eol=CRLF, only the default was not set.

dietmarw commented 9 years ago

OK this is a hint. I think I know what's going on ... but not sure how to solve it yet.

dietmarw commented 9 years ago

OK finally fixed this. When using os.linesep (normally discouraged in combination with writing files but we like to explicitly override the default os.linesep) one needs to set newline='' in io.open. Fixed in 2e3d580eb271

thorade commented 9 years ago

Awesome, works for me