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.

Title: case sensitivity in open() arguments
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.8, Python 3.7, Python 3.6
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.smith, iritkatriel, sean.grogan
Priority: normal Keywords:

Created on 2020-12-02 16:09 by sean.grogan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg382322 - (view) Author: Sean Grogan (sean.grogan) Date: 2020-12-02 16:09
I was stuck on a problem today using an open statement where I was trying to open a file for writing


    with open("RESULTS.CSV", "W") as csvfile:
        csvwriter = csv.writer(csvfile)
        csvwriter.writerow(["X", "Y"])

I did not notice I had the mode W in upper case. I am not sure if there is a legacy reason for only allowing lower case arguments here but I think a quick note in the documentation that it's case sensitive or a check (or note) when throwing an error would be helpful?  such as 

    ValueError: invalid mode: 'W' -- your case appears to be an upper case, please ensure the case of the mode is correct


    ValueError: invalid mode: 'W' -- note the mode is case sensitive

could be helpful?
msg382436 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-12-03 18:21
Although I'm not sure the existing message needs changing, if a change is going to be made I think listing the valid option characters might be more useful.
msg410716 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-16 19:34
I also think the current error message and docs are clear enough. Things are usually case sensitive, and we don't state that in docs. 

Specifying the list of modes in the error message is possible, but I expect that we will get complaints about variations we did not list (why do you mention only "r" and "w" when "rw" is also fine?)
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86709
2022-01-23 19:49:16iritkatrielsetstatus: pending -> closed
stage: resolved
2022-01-16 19:34:57iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg410716

resolution: wont fix
2020-12-03 18:21:46eric.smithsetnosy: + eric.smith
messages: + msg382436
2020-12-02 16:09:30sean.grogancreate