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

Created on 2020-12-02 16:09 by sean.grogan, last changed 2020-12-03 18:21 by eric.smith.

Messages (2)
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.
Date User Action Args
2020-12-03 18:21:46eric.smithsetnosy: + eric.smith
messages: + msg382436
2020-12-02 16:09:30sean.grogancreate