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

Serhiy Storchaka storchaka at gmail.com
Sat Mar 7 14:27:57 CET 2015


On 05.03.15 15:40, anatoly techtonik wrote:
> While looking at the code like:
>
>      'os': sysinfo['os'].decode('utf-8'),
>      'hostname': sysinfo['hostname'].decode('utf-8'),
>
> I can't really read if the result will be unicode or binary string in
> utf-8. It would be more convenient for readability to have these
> instead:
>
>      bytes.from(encoding) -> unicode
>      unicode.to(encoding) -> bytes

Don't write sysinfo['os'].decode('utf-8') if it confuses you. Write 
str(sysinfo['os'], 'utf-8').




More information about the Python-ideas mailing list