Last active
August 29, 2015 14:02
-
-
Save pfreixes/4aea1c5642c85b80efe8 to your computer and use it in GitHub Desktop.
A not negligible difference between Python 2 and Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Programs not ported to Python 3 that they are using specific | |
operations with strings could raise undesirable bugs""" | |
>>> title = "Open binary file with python 3" | |
>>> fd = open("/tmp/wut.png", "rb") | |
>>> b = fd.read() | |
>>> type(b) | |
<class 'bytes'> | |
>>> b[0] == "\x89" | |
False | |
>>> title = "Open binary file with python 2" | |
>>> fd = open("/tmp/wut.png", "rb") | |
>>> b = fd.read() | |
>>> type(b) | |
<type 'str'> | |
>>> b[0] == "\x89" | |
True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment