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

Serhiy Storchaka storchaka at gmail.com
Tue Mar 28 02:57:50 EDT 2017


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 it clear when you've reached the end
> of a value, it seems entirely reasonable for a parser to just
> stop reading from the stream at that point, and leave whatever
> remains for the application to deal with as it sees fit. The
> application can then choose to immediately read another value
> from the same stream if it wants.

You can determine the end of integer literal only after reading a 
character past the end of the integer literal. This there is not a way 
to put back a character, it will be lost for following readers.

And currently json.load() is implemented by reading all file content at 
once and passing it to json.loads(). Different implementation would be 
much more complex (if we don't want to loss the performance).




More information about the Python-ideas mailing list