Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-29 Thread Wes Turner
On Mon, Mar 27, 2017 at 4:27 PM, Wes Turner wrote: > > > On Mon, Mar 27, 2017 at 10:34 AM, Chris Barker > wrote: > >> On Mon, Mar 27, 2017 at 7:59 AM, Paul Moore wrote: >> >>> On 27 March 2017 at 15:40, Ram Rachum wrote: >>> > Another idea: Maybe make json.load and json.dump support Path objec

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Serhiy Storchaka
On 28.03.17 02:35, Greg Ewing wrote: Paul Moore wrote: Is this a well-defined idea? ... There's nothing describing how multiple values would be stored in the same file/transmitted in the same stream. I think this is something that's outside the scope of the spec. But since the grammar makes i

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Victor Stinner
2017-03-27 17:04 GMT+02:00 Steven D'Aprano : > Of course pathlib can already read JSON, or for that matter ReST text > or JPG binary files. It can read anything as text or bytes, including > JSON: > > some_path.write_text(json.dumps(obj)) > json.loads(some_path.read_text()) Note: You should specif

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Greg Ewing
Paul Moore wrote: Is this a well-defined idea? ... There's nothing describing how multiple values would be stored in the same file/transmitted in the same stream. I think this is something that's outside the scope of the spec. But since the grammar makes it clear when you've reached the end of

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Philipp A.
Ram Rachum schrieb am Mo., 27. März 2017 um 16:42 Uhr: > Another idea: Maybe make json.load and json.dump support Path objects? > yes, all string-path expecting stdlib APIs should support PEP 519 https://www.python.org/dev/peps/pep-0519/ ___ Python-id

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Wes Turner
FWIW, pyline could produce streaming JSON w/ json.dumps(indent=0), but because indent>0, there are newlines. pydoc json | pyline '{"a":l} if "json" in l.lower() else None' -O json pydoc json | pyline -r '.*JSON.*' 'rgx and line' -O json It's a similar issue: what are good default JSON enc

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Wes Turner
On Mon, Mar 27, 2017 at 10:34 AM, Chris Barker wrote: > On Mon, Mar 27, 2017 at 7:59 AM, Paul Moore wrote: > >> On 27 March 2017 at 15:40, Ram Rachum wrote: >> > Another idea: Maybe make json.load and json.dump support Path objects? >> >> If they currently supported filenames, I'd say that's a

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread David Mertz
This is a better link: https://en.m.wikipedia.org/wiki/JSON_Streaming On Mar 27, 2017 3:45 PM, "David Mertz" wrote: > The format JSON lines (http://jsonlines.org/) is pretty widely used, but > is an extension of JSON itself. Basically, it's the idea that you can put > one object per physical lin

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread David Mertz
The format JSON lines (http://jsonlines.org/) is pretty widely used, but is an extension of JSON itself. Basically, it's the idea that you can put one object per physical line to allow incremental reading or spending of objects. It's a good idea, and I think the `json` module should support it. Bu

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Paul Moore
On 27 March 2017 at 17:43, Bruce Leban wrote: > the ability to read one json object from the input rather than reading the > entire input Is this a well-defined idea? From a quick read of the JSON spec (which is remarkably short on details of how JSON is stored in files, etc) the only reference I

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Chris Barker
On Mon, Mar 27, 2017 at 9:43 AM, Bruce Leban wrote: > I'm not in favor of this idea for the reason mentioned by many of the > other posters. BUT ... this does bring up something missing from json > readers: *the ability to read one json object from the input rather than > reading the entire input

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Bruce Leban
I'm not in favor of this idea for the reason mentioned by many of the other posters. BUT ... this does bring up something missing from json readers: *the ability to read one json object from the input rather than reading the entire input* and attempting to interpret it as one object. For my use cas

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ethan Furman
On 03/27/2017 08:04 AM, Steven D'Aprano wrote: On Mon, Mar 27, 2017 at 02:50:38PM +0200, Ram Rachum wrote: What do you think about adding methods pathlib.Path.write_json and pathlib.Path.read_json , similar to write_text, write_bytes, read_text, read_bytes? That's not pathlib's responsibilit

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Paul Moore
On 27 March 2017 at 15:48, Eric V. Smith wrote: > On 3/27/17 10:40 AM, Ram Rachum wrote: >> >> Another idea: Maybe make json.load and json.dump support Path objects? > > > json.dump requires open file objects, not strings or Paths representing > filenames. > > But does this not already do what you

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Eric V. Smith
On 3/27/17 10:40 AM, Ram Rachum wrote: Another idea: Maybe make json.load and json.dump support Path objects? json.dump requires open file objects, not strings or Paths representing filenames. But does this not already do what you want: Path('foo.json').write_text(json.dumps(obj)) ? Eric.

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Chris Barker
On Mon, Mar 27, 2017 at 7:59 AM, Paul Moore wrote: > On 27 March 2017 at 15:40, Ram Rachum wrote: > > Another idea: Maybe make json.load and json.dump support Path objects? > > If they currently supported filenames, I'd say that's a reasonable > extension. Given that they don't, it still seems l

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Steven D'Aprano
On Mon, Mar 27, 2017 at 02:50:38PM +0200, Ram Rachum wrote: > Hi guys, > > What do you think about adding methods pathlib.Path.write_json and > pathlib.Path.read_json , similar to write_text, write_bytes, read_text, > read_bytes? > > This would make writing / reading JSON to a file a one liner in

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Paul Moore
On 27 March 2017 at 15:40, Ram Rachum wrote: > Another idea: Maybe make json.load and json.dump support Path objects? If they currently supported filenames, I'd say that's a reasonable extension. Given that they don't, it still seems like more effort than it's worth to save a few characters

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Markus Meskanen
Another idea: Maybe make json.load and json.dump support Path objects? Much better. Or maybe add json.load_path and dump_path ___ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: ht

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Serhiy Storchaka
On 27.03.17 15:50, Ram Rachum wrote: Hi guys, What do you think about adding methods pathlib.Path.write_json and pathlib.Path.read_json , similar to write_text, write_bytes, read_text, read_bytes? This would make writing / reading JSON to a file a one liner instead of a two-line with clause.

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Donald Stufft
> On Mar 27, 2017, at 10:36 AM, Paul Moore wrote: > > On 27 March 2017 at 15:33, Donald Stufft > wrote: >> What do you think about adding methods pathlib.Path.write_json and >> pathlib.Path.read_json , similar to write_text, write_bytes, read_text, >> read_bytes? >> >>

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Another idea: Maybe make json.load and json.dump support Path objects? On Mon, Mar 27, 2017 at 4:36 PM, Paul Moore wrote: > On 27 March 2017 at 15:33, Donald Stufft wrote: > > What do you think about adding methods pathlib.Path.write_json and > > pathlib.Path.read_json , similar to write_text,

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Paul Moore
On 27 March 2017 at 15:33, Donald Stufft wrote: > What do you think about adding methods pathlib.Path.write_json and > pathlib.Path.read_json , similar to write_text, write_bytes, read_text, > read_bytes? > > > > -1, I also think that write_* and read_* were mistakes to begin with. Text is (much)

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Donald Stufft
> On Mar 27, 2017, at 8:50 AM, Ram Rachum wrote: > > What do you think about adding methods pathlib.Path.write_json and > pathlib.Path.read_json , similar to write_text, write_bytes, read_text, > read_bytes? > -1, I also think that write_* and read_* were mistakes to begin with. — Donald S

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Paul Moore
On 27 March 2017 at 13:50, Ram Rachum wrote: > This would make writing / reading JSON to a file a one liner instead of a > two-line with clause. That hardly seems like a significant benefit... Paul ___ Python-ideas mailing list [email protected]

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Oh, and also it saves you from having to import json. On Mon, Mar 27, 2017 at 2:50 PM, Ram Rachum wrote: > Hi guys, > > What do you think about adding methods pathlib.Path.write_json and > pathlib.Path.read_json , similar to write_text, write_bytes, read_text, > read_bytes? > > This would make w

[Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Hi guys, What do you think about adding methods pathlib.Path.write_json and pathlib.Path.read_json , similar to write_text, write_bytes, read_text, read_bytes? This would make writing / reading JSON to a file a one liner instead of a two-line with clause. Thanks, Ram. __