-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
BOM incorrectly inserted before writing, after seeking in text file #67171
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
Comments
If you open a text file for append, but then perform any form of seeking, before attempting to write to the file, it will cause the BOM to be written before you text. See the attached file for an example. If you run the test, take a look at the output file, and you'll notice the UTF16 BOM gets written out before each number. I'm running a 2014 iMac with Yosemite. |
bpo-5006 was supposed to take care of this, but it has a flaw IMO: |
This is a limitation more than a bug. When you seek to the start of the file, the encoder is reset because Python thinks you are gonna to write there. If you remove the call to @Amaury, whence can only be zero there: |
It's more than a limitation, because if I call This also means that it's impossible to seek in a text file that you want to append to. I've had to work around this by opening the file as binary, manually writing the BOM, and writing the strings as encoded bytes. |
Here is a patch. |
New changeset 946740824eaf by Antoine Pitrou in branch '3.4': New changeset 3583e5191b96 by Antoine Pitrou in branch 'default': |
Fix is pushed. Thanks for the report! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: