[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-16 Thread Isaac Johnson


Isaac Johnson  added the comment:

Well that is how it works with open. It is implemented in the io module and  
added to builtins.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-16 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

True, but you did say it would be with the io module in your original 
suggestion.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-16 Thread Isaac Johnson


Isaac Johnson  added the comment:

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-16 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

You can create a module on PyPI. If it becomes popular we could consider 
including in the stdlib.

--
nosy: +serhiy.storchaka
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-16 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This looks similar to a previous proposal

https://discuss.python.org/t/enum-for-open-modes/2445

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-15 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

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, `|` the bitwise-or operator, and how to import 
File from the io module.

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?

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-15 Thread Isaac Johnson


Change by Isaac Johnson :


--
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-15 Thread Isaac Johnson


Isaac Johnson  added the comment:

I'm currently working on implementing this. It will probably be a few weeks.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46766] Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.

2022-02-15 Thread Isaac Johnson


New submission from Isaac Johnson :

I think it would be great for something like this to be with the IO module. It 
will improve code readability.

--
components: Library (Lib)
messages: 413315
nosy: isaacsjohnson22
priority: normal
severity: normal
status: open
title: Add a class for file operations so a syntax such as open("file.img", 
File.Write | File.Binary | File.Disk) is possible.
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com