Re: [Python-Dev] Why does base64 return bytes?
On Tue, Jun 14, 2016 at 09:40:51PM -0700, Guido van Rossum wrote:
I'm officially on vacation, but I was surprised that people now assume RFCs, which specify internet protocols, would have a bearing on programming languages. (With perhaps an exception for RFCs that specifically specify how programming languages or their libraries should treat certain specific issues -- but I found no evidence that this RFC is doing that.)
Sorry to disturb your vacation! I hoped that there might have been a nice simple answer, like "the main use-case for Base64 is the email module, which needs bytes, and thus it was decided". Or even "because backwards compatibility". Thanks to everyone for their constructive comments, and expecially Mark for digging up the original discussion on the Python-3000 list. I'm satisfied that the choice made by Python is the right choice, and that it meets the spirit (if, arguably, not the letter) of the RFC. -- Steve
In that case could we just add a base64_text() method somewhere? Who would like to measure whether it would be a win? On Wed, Jun 15, 2016 at 8:34 AM Steven D'Aprano <steve@pearwood.info> wrote:
I'm officially on vacation, but I was surprised that people now assume RFCs, which specify internet protocols, would have a bearing on
On Tue, Jun 14, 2016 at 09:40:51PM -0700, Guido van Rossum wrote: programming
languages. (With perhaps an exception for RFCs that specifically specify how programming languages or their libraries should treat certain specific issues -- but I found no evidence that this RFC is doing that.)
Sorry to disturb your vacation!
I hoped that there might have been a nice simple answer, like "the main use-case for Base64 is the email module, which needs bytes, and thus it was decided". Or even "because backwards compatibility".
Thanks to everyone for their constructive comments, and expecially Mark for digging up the original discussion on the Python-3000 list. I'm satisfied that the choice made by Python is the right choice, and that it meets the spirit (if, arguably, not the letter) of the RFC.
-- Steve _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/dholth%40gmail.com
On 15 June 2016 at 13:53, Daniel Holth <dholth@gmail.com> wrote:
In that case could we just add a base64_text() method somewhere? Who would like to measure whether it would be a win?
"Just adding" a method in the stdlib, means we'd have to support it long term (backward compatibility). So by the time such an experiment determined whether it was worth it, it'd be too late. Finding out whether users/projects typically write such a helper function for themselves would be a better way of getting this information. Personally, I suspect they don't, but facts beat speculation. Of course, "not every one liner needs to be a stdlib function" applies here too. Paul
On Wed, Jun 15, 2016 at 12:53:15PM +0000, Daniel Holth wrote:
In that case could we just add a base64_text() method somewhere? Who would like to measure whether it would be a win?
Just call .decode('ascii') on the output of base64.b64encode. Not every one-liner needs to be a standard function. -- Steve
Paul Moore:
Finding out whether users/projects typically write such a helper function for themselves would be a better way of getting this information. Personally, I suspect they don't, but facts beat speculation.
Well, I did. It was necessary to get 2to3 conversion to work(*). I turned every occurence of E.encode('base-64') and E.decode('base-64') into helper function calls that for Python 3 did: b64encode(E).decode('ascii') and b64decode(E.encode('ascii')) (Or something similar, I don't have the code in front of me.) Leaving out .decode/.encode('ascii') would simply not have worked. That would just be asking for TypeError's. regards, Anders (*) Yes, I use 2to3, believe it or not. Maintaining Python 2 code and doing an automated conversion to Python 3 as needed.
Steven D'Aprano wrote:
I'm satisfied that the choice made by Python is the right choice, and that it meets the spirit (if, arguably, not the letter) of the RFC.
IMO it meets the letter (if you read it a certain way) but *not* the spirit. -- Greg
participants (5)
-
Anders J. Munch -
Daniel Holth -
Greg Ewing -
Paul Moore -
Steven D'Aprano