kynan / nbstripout

strip output from Jupyter and IPython notebooks
Other
1.19k stars 95 forks source link

add newline param to output_stream and file open #125

Closed ooiM closed 4 years ago

ooiM commented 4 years ago

Purpose

To solve the issue #110. I faced the same problem on my Windows environment. nbstripout converts my ipynb file newline from LF to CRLF when I committing.

Bug Cause

About the newline parameter of open method and TextIOWrapper method

When writing output to the stream, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep.

https://docs.python.org/3/library/io.html#io.TextIOWrapper https://docs.python.org/3/library/functions.html#open-newline-parameter

os.linesep is

The string used to separate (or, rather, terminate) lines on the current platform. This may be a single character, such as '\n' for POSIX, or multiple characters, for example, '\r\n' for Windows.

https://docs.python.org/3/library/os.html#os.linesep

Bug Fix

Add newline='' parameter to open method and TextIOWrapper method

If newline is '' or '\n', no translation takes place.

https://docs.python.org/3/library/io.html#io.TextIOWrapper https://docs.python.org/3/library/functions.html#open-newline-parameter


This is my first pull request.
So I don't know if this is right way of pull request. If there is any problem, please tell me.