bytes() or .encode() for encoding str's as bytes?

Marko Rauhamaa marko at pacujo.net
Fri Aug 31 14:44:45 EDT 2018


Malcolm Greene <python at bdurham.com>:
> Is there a benefit to using one of these techniques over the other?
> Is one approach more Pythonic and preferred over the other for
> style reasons?
> message = message.encode('UTF-8')
> message = bytes(message, 'UTF-8')

I always use the former. I wonder why that is. I guess the aesthetic
rule is something along the lines: use a dot if you can.


Marko



More information about the Python-list mailing list