A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-April/088717.html below:

[Python-Dev] Dropping bytes "support" in json

[Python-Dev] Dropping bytes "support" in json [Python-Dev] Dropping bytes "support" in jsonAlexandre Vassalotti alexandre at peadrop.com
Tue Apr 14 01:44:38 CEST 2009
On Mon, Apr 13, 2009 at 5:25 PM, Daniel Stutzbach
<daniel at stutzbachenterprises.com> wrote:
> On Mon, Apr 13, 2009 at 3:02 PM, "Martin v. Löwis" <martin at v.loewis.de>
> wrote:
>>
>> > True, I can always convert from bytes to str or vise versa.
>>
>> I think you are missing the point. It will not be necessary to convert.
>
> Sometimes I want bytes and sometimes I want str.  I am going to be
> converting some of the time. ;-)
>
> Below is a basic CGI application that assumes that json module works with
> str, not bytes.  How would you write it if the json module does not support
> returning a str?
>
> print("Content-Type: application/json; charset=utf-8")
> input_object = json.loads(sys.stdin.read())
> output_object = do_some_work(input_object)
> print(json.dumps(output_object))
> print()
>

Like this?

print("Content-Type: application/json; charset=utf-8")
input_object = json.loads(sys.stdin.buffer.read())
output_object = do_some_work(input_object)
stdout.buffer.write(json.dumps(output_object))


-- Alexandre
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4