-
-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent CRLF behaviour between Windows and Linux #1362
Comments
Thanks for the report, @daviewales. You're right, this is incorrect. Ideally it would detect the csv options and set them on the source sheet so it would save in an identical format (though derived sheets wouldn't inherit this format, which may or may not be desired). |
The strange thing is that on Linux, it does: |
Interesting. This is due to |
Fixes saulpw#1362 According to the docs for csv.writer: > If csvfile is a file object, it should be opened with newline='' > https://docs.python.org/3/library/csv.html#csv.writer Additionally: > If newline='' is not specified, newlines embedded inside quoted fields will > not be interpreted correctly, and on platforms that use \r\n linendings on > write an extra \r will be added. It should always be safe to specify > newline='', since the csv module does its own (universal) newline handling. > https://docs.python.org/3/library/csv.html#id3 This commit adds `newline=None` as a keyword argument for `open_text` in `path.py`. It then uses this new keyword argument when opening a file for writing in `loaders/csv.py`
@saulpw I did some more digging, and I think the issue is because the CSV file should be opened with See this note on the csv.writer docs: I'll send through a pull request with a fix. |
Fixes saulpw#1362 According to the docs for csv.writer: > If csvfile is a file object, it should be opened with newline='' > https://docs.python.org/3/library/csv.html#csv.writer Additionally: > If newline='' is not specified, newlines embedded inside quoted fields will > not be interpreted correctly, and on platforms that use \r\n linendings on > write an extra \r will be added. It should always be safe to specify > newline='', since the csv module does its own (universal) newline handling. > https://docs.python.org/3/library/csv.html#id3 This commit adds `newline=None` as a keyword argument for `open_text` in `path.py`. It then uses this new keyword argument when opening a file for writing in `loaders/csv.py`
Fixes #1362 According to the docs for csv.writer: > If csvfile is a file object, it should be opened with newline='' > https://docs.python.org/3/library/csv.html#csv.writer Additionally: > If newline='' is not specified, newlines embedded inside quoted fields will > not be interpreted correctly, and on platforms that use \r\n linendings on > write an extra \r will be added. It should always be safe to specify > newline='', since the csv module does its own (universal) newline handling. > https://docs.python.org/3/library/csv.html#id3 This commit adds `newline=None` as a keyword argument for `open_text` in `path.py`. It then uses this new keyword argument when opening a file for writing in `loaders/csv.py`
Small description
If I open a CSV with
LF
line endings in VisiData on Windows, make a change, then save the file, I getCRCRLF
line endings.Note that this is not just
CRLF
line endings, which is what you get on Linux (see #1076). Note that there are somehow twoCR
characters before theLF
!Expected result
The line endings should either be
LF
(preserve original) orCRLF
(Python and VisiData default for CSV writer on Linux).The line endings should not be
CRCRLF
...Actual result with screenshot
If you get an unexpected error, please include the full stack trace that you get with
Ctrl-E
.Steps to reproduce with sample data and a .vd
Original file (note the LF (
0a
) line ending:lf.csv
New file (note the CRCRLF (
0d 0d 0a
) line ending!)lf.csv
CommandLog (zipped):
lf.zip
Additional context
Please include the version of VisiData: saul.pw/VisiData v2.7.1
The text was updated successfully, but these errors were encountered: