[Python-ideas] .from and .to instead of .encode and .decode

Giampaolo Rodola' g.rodola at gmail.com
Sun Mar 8 14:07:10 CET 2015


On Sat, Mar 7, 2015 at 2:42 PM, Luciano Ramalho <luciano at ramalho.org> wrote:

> On Sat, Mar 7, 2015 at 8:41 AM, Chris Angelico <rosuav at gmail.com> wrote:
> > If it says "decode", the result is a Unicode string. If it says
> > "encode", the result is bytes. I'm not sure what is difficult here.
>
> Yep. When I teach, I use this mnemonic, which I can now quote from my
> book [1] ;-)
>
> [TIP]
> ====
> If you need a memory aid to distinguish `.decode()` from `.encode()`,
> convince yourself that a Unicode `str` contains "human" text, while
> byte sequences can be cryptic machine core dumps. Therefore, it makes
> sense that we *decode* `bytes` to `str` to get human readable text,
> and we *encode* text to `bytes` for storage or transmission.
> ====


This is a great advice (and yes, I also often get confused by the two).


-- 
Giampaolo - http://grodola.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150308/ea0727f4/attachment.html>


More information about the Python-ideas mailing list