Skip to content
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

Format string in output file with plain line-ending character instead of os.linesep #266

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

rwxayheee
Copy link
Contributor

@rwxayheee rwxayheee commented Dec 7, 2024

The issue only affects Windows PowerShell. In some files written by Meeko, each line has double the line-ending characters. This is likely because the Python built-in function f.open() by default translates '\r\n' (os.linesep on Windows) to '\r\r\n' when writing the file, which will be read as '\n\n' when the file is re-opened.

https://docs.python.org/3/library/functions.html#open

When writing output to the stream, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '' or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string.

This PR replaces all eol by the plain line-ending character '\n'. Another possible solution is to always write without translation, i.e. f.open(newline='') but that isn't the default. Thanks to Nicole Benson (Fuchs lab, OSU) for bringing this to our attention.

@rwxayheee rwxayheee requested a review from diogomart December 7, 2024 01:00
Copy link
Contributor

@diogomart diogomart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :-)

@rwxayheee
Copy link
Contributor Author

Thanks! Merging to develop

@rwxayheee rwxayheee merged commit 06f61eb into forlilab:develop Dec 7, 2024
1 check passed
@rwxayheee rwxayheee deleted the cross_platform_newline branch December 7, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants