Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Savetxt may ignore newline character on Windows #5503

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

Closed
wants to merge 4 commits into from

Conversation

charris
Copy link
Member

@charris charris commented Jan 25, 2015

Under some circumstances savetxt ignores the newline character on Python
2.7 running on Windows: If newline is set to '\n', actually '\n\r' is
written, because of the linesep conversion of file.write.

Closes #3975.

Cleanup of #3976.

816-8055 and others added 4 commits January 25, 2015 11:49
Under some circumstances savetxt ignores the newline character on Python
2.7 running on Windows: If newline is set to '\n', actually '\n\r' is
written, because of the linesep conversion of file.write.

Closes numpy#3975.
Tests the correct usage of newline in savetxt.

See numpy#3976
Use NamedTemporaryFile in TestSaveTxt.test_newline.
Use asbytes in TestSaveTxt.test_newline for Python 3 compatibility.
Update savetxt documentation of 'newline'.
@charris
Copy link
Member Author

charris commented Jan 25, 2015

@juliantaylor Could you check the use of NamedTemporaryFile?

@charris
Copy link
Member Author

charris commented Jan 25, 2015

Needs testing on windows and mac.

@juliantaylor
Copy link
Contributor

opening files as binary is the opposite of what we should do, its the cause of all our unicode issues in the text functions. If its text open it as text.
I'm not clear on what exactly the problem is, maybe its just missing universal_newlines=True?

@charris
Copy link
Member Author

charris commented Jan 25, 2015

I have the sense that more control over the line separator is the point here. With Python 3 is it is possible to specify the separator when a text file is opened, but not in Python 2. This PR leaves me uneasy, so alternatives/discussion is needed.

@homu
Copy link
Contributor

homu commented Jul 9, 2015

☔ The latest upstream changes (presumably #6031) made this pull request unmergeable. Please resolve the merge conflicts.

@charris charris closed this Sep 19, 2018
@charris charris deleted the cleanup-gh-3976 branch September 19, 2018 14:41
@ChrisIdema
Copy link

ChrisIdema commented Mar 24, 2021

After more than 6 years it is still not fixed.
There is a workaround by manually opening the file with 'wb':

 with open('file.csv', 'wb') as f:
        np.savetxt(f, array, delimiter=",",newline='\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

savetxt ignores newline on Python 2.7
6 participants