Python 2 or 3

Chris Angelico rosuav at gmail.com
Sat Dec 3 05:44:22 EST 2011


On Sat, Dec 3, 2011 at 9:04 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> If you can deal with the difference between these two lines without
> getting confused:
>
> print md5.md5("spam").hexdigest()  # Python 2.x
> print(hashlib.md5("spam").hexdigest())  # Python 3.x

The second line needs to be:
print(hashlib.md5("spam".encode()).hexdigest())

Relatively insignificant differences, since Python 2 and Python 3 both
support both bytes and unicode strings. The only difference is that
Py3 makes Unicode the default, forcing you to be explicit when you
want bytes.

ChrisA



More information about the Python-list mailing list