Tuesday, April 11, 2017

Python 3 vs. Python 2.7

I decided it was finally time to move to Python 3 from Python 2. Having done so, I don't see why I wasn't using Python 3 years ago, although my code worked just fine so it wasn't really a big deal.

Python 3 has two big advantages, and there's also a third reason you should be using it by now.

  1. Unicode: You don't have to worry about catching Unicode characters in string types anymore, Python 3 does it for you. This is a concern for me with web scraping. So much easier.
  2. For years I've read about the following dilemma in OSX, with no solution: 
    1. If you DON'T install your own copy of Python 2, you are modifying the OS's copy of important libraries and such, and that can cause problems.
    2. If you DO install your own copy of Python 2, you then have two versions of Python 2 on your computer, and that can cause problems.
    The solution... just install Python 3. These two problems aren't even relevant.
  3. But, the best part was that about 99% of my code still works as is. All I've had to do so far is change print statements, from print "Print this Py2!"  to  print("Print this Py3!"), and get rid of the Unicode error catching.