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
Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible. #90922
Comments
I think it would be great for something like this to be with the IO module. It will improve code readability. |
I'm currently working on implementing this. It will probably be a few weeks. |
I'm sorry, I don't see why you think this will improve code readability. I also expect it will be harder to teach than the current code. open("file.img", "wb") just needs the user to learn about reading and writing files, and the difference between binary and text files. It works the same way in probably dozens of different languages. open("file.img", File.Write | File.Binary | File.Disk) needs the beginner to learn the same details, plus they have to learn about this mystery File object, classes, dot notation, My guess is that File.Write etc are just enums equivalent to strings 'w' and 'b', but what's File.Disk? What else does this File object do? |
This looks similar to a previous proposal |
You can create a module on PyPI. If it becomes popular we could consider including in the stdlib. |
Well it wouldn't need to be imported. I was working on including it inside builtins like open(). It wouldn't be very convenient if it needed to be imported. |
True, but you did say it would be with the io module in your original suggestion. |
Well that is how it works with open. It is implemented in the io module and added to builtins. |
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: