<div class="gmail_quote">On Mon, Apr 13, 2009 at 3:02 PM, "Martin v. Löwis" <span dir="ltr"><<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">> True, I can always convert from bytes to str or vise versa.<br>
<br>
</div>I think you are missing the point. It will not be necessary to convert.</blockquote><div><br>Sometimes I want bytes and sometimes I want str. I am going to be converting some of the time. ;-)<br><br>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?<br>
<br>print("Content-Type: application/json; charset=utf-8")<br>input_object = json.loads(sys.stdin.read())<br>output_object = do_some_work(input_object)<br>print(json.dumps(output_object))<br>print()<br><br></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The questions is: which of them is more appropriate, if, what you want,<br>
is bytes. I argue that the second form is better, since it saves you<br>
an encode invocation.<br>
</blockquote></div><br>If what you want is bytes, encoding has to happen somewhere. If the json module has some optimizations to do the encoding at the same time as the serialization, great. However, based on the original post of this thread, it sounds like that code doesn't exist or doesn't work correctly.<br>
<br>What's the benefit of preventing users from getting a str out if that's what they want?<br><blockquote style="margin: 1.5em 0pt;">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>