This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Writing capital letters with csvwriter.writerow changes the csv file format
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Stefan Vasilev, eric.smith, paul.moore, r.david.murray, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-06-12 13:01 by Stefan Vasilev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg319378 - (view) Author: Stefan Vasilev (Stefan Vasilev) Date: 2018-06-12 13:01
import csv
csv.writer(open('./file.csv', 'a', newline='')).writerow(['ID', 0])

If you try to open file.csv with Excel on Windows 10 it says:
The file format and extension of 'file.csv' don't match. The file could be corrupted or unsafe. Unless you trust its source don't open it. Do you want to open it anyway.

When you click 'Yes', another msgbox appears saying:
Excel has detected that 'file.csv' is a SYLK file, but cannot load it. Either the file has errors or it is not a SYLK fyle format. Click OK to try to open the file in a different format.

When you click on 'OK' it opens it as expected.

The strange thing is that if you use the following code, there are no problems opening it:
import csv
csv.writer(open('./file.csv', 'a', newline='')).writerow(['Id', 0])
msg319380 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-06-12 13:41
It doesn't look like this has anything to do with Python.  This sounds like a question more appropriate for an Excel help forum.
msg319383 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-12 13:56
Both CSV and SYLK are text formats used by Excel.
msg319393 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-12 15:37
This is happening because the string "ID" is special to the SYLK format: https://en.wikipedia.org/wiki/SYmbolic_LinK_(SYLK)
msg319435 - (view) Author: Stefan Vasilev (Stefan Vasilev) Date: 2018-06-13 07:24
Ah, I see now. What a coincidence :)
Thank you for explaining that!
History
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78025
2018-06-13 09:31:28eric.smithsetresolution: works for me -> not a bug
2018-06-13 07:24:59Stefan Vasilevsetresolution: not a bug -> works for me
messages: + msg319435
2018-06-12 15:37:59eric.smithsetnosy: + eric.smith
messages: + msg319393
2018-06-12 13:56:45serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg319383

resolution: not a bug
stage: resolved
2018-06-12 13:41:15r.david.murraysetnosy: + r.david.murray
messages: + msg319380
2018-06-12 13:01:04Stefan Vasilevcreate