[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library fil
From: |
Bruno Haible |
Subject: |
Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files. |
Date: |
Thu, 28 Mar 2024 03:29:18 +0100 |
Collin Funk wrote:
> With open() using binary mode with encoding='utf-8' causes a failure:
>
> with open('test.txt', 'wb', encoding='utf-8') as file:
> file.write('abc')
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: binary mode doesn't take an encoding argument
Oops, you're right. My mistake. And likewise for 'rb'.
> # Write files with '\n' as newline character.
> with open('file.txt', 'w', encoding='utf-8', newline='\n') as file:
Yes, you're right. I've committed a fix now. Sorry.
> From the documentation from open, it seems the best way to deal with
> this is for reading files [2]:
>
> # Accepts '\n', '\r', '\r\n' as newline.
> with open('file.txt', 'r', encoding='utf-8') as file:
> data = file.read()
They can recommend it. But what we want here is to recognize Unix
newlines, not macOS 9 newlines or DOS/Windows newlines. It should
behave like gnulib-tool.sh, and thus newline='\n' is appropriate here.
Bruno
- [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Collin Funk, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Collin Funk, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Bruno Haible, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Bruno Haible, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Collin Funk, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files., Collin Funk, 2024/03/27
- Re: [PATCH] gnulib-tool.py: Inline 'sed' invocations used on library files.,
Bruno Haible <=
- Newline handling, Collin Funk, 2024/03/27
- Re: Newline handling, Bruno Haible, 2024/03/27
- Re: Newline handling, Collin Funk, 2024/03/28