It's been brought up a few times eg:  
https://github.com/python/cpython/pull/12465

but I really think it's time to be re-considered.


Specifically I love being able to use 
`asyncio.to_thread(pathlib.Path(...).read_text, encoding="utf8")` It does 
exactly the right thing for me! It's great because it interacts with the event 
loop as few times as possible and uses only the RAM absolutely required.


I'm looking to be able to do something like 
`asyncio.to_thread(pathlib.Path(...).json)`

defined as:

```python
def json(self):
    import json

    with self.open("rb") as f:
        return json.load(f)
```

while this may seem simple to implement in my own code it handles a lot of 
stuff for me!, Specifically PEP 538, minimal interactions with the asyncio 
waker pipe, the minimal amount of ram, etc etc.


You might ask - if json why not .html() and .xml() and .csv() ? Well each of 
these formats require specific configuration - eg do you want defused or 
regular exploding xml? Do you want excel style CSV or GNU style CSV? AFAIK json 
is the only format with a one shot zeroconf bytes -> structure format, and so 
makes it worthy of the pathlib shortcut.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/7GYEHWUNPOJZLEWJ5CZCNUVJYEDLGDPM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to