[Python-Dev] Why can't I encode/decode base64 without importing a module? (original) (raw)

R. David Murray rdmurray at bitdance.com
Mon Apr 22 17:31:02 CEST 2013


On Mon, 22 Apr 2013 09:50:14 -0400, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:

On Mon, Apr 22, 2013 at 7:39 AM, Calvin Spealman <ironfroggy at gmail.com> wrote: > if two lines is cumbersome, you're in for a cumbersome life a programmer.

Other encodings are either missing completely from the stdlib, or have corrupted behavior. For example, stringescape is gone, and unicodeescape doesn't make any sense anymore -- python code is text, not bytes, so why does 'abc'.encode('unicodeescape') return bytes? I don't think this change was thought through completely before it was implemented.

We use unicode_escape (actually raw_unicode_escape) in the email package, and there we are converting between string and bytes. It is used as an encoder when we are supposed to have ASCII input but have other stuff, and need ASCII output and don't want to lose information. So yes, that encoder does still make sense. It would also be useful as a transform function, but as someone has pointed out there's an issue for that.

--David



More information about the Python-Dev mailing list