Page 422 -
P. 422

leftovers


          #2: Using Python 2


           If you remember way back in the Readme, we stated we were
           using release 3 of Python in this book. Of course, there’s much
           more to Python that just release 3, as the previous version of the
           language, release 2, is still very, very popular.
          And rightly so. Python 2 has been around for nearly a decade
           and has an impressive collection of technologies built around it,
           including Google’s App Engine, the Django Web Framework, Zope’s
           Content Management System, and the Twisted Networking Libraries (to
           name just a few).
           Despite all the Python 2 goodness out there, we still went with
           release 3 for this book and our reasoning was very simple: better to
           go with the future than settle on the past. The good folks that bring the
           world Python have stated that Python 3 is where all the cool, new
           stuff will happen with the language. Release 2 has entered what’s
           known as bug-fix mode only: if something is found in 2 that is broken,
           it’ll be fixed, but no new features will be added.
          And here’s the good news: there’s not much difference between the
           code you’ve been writing for Python 3 and what you would write
           for release 2, should you find yourself in the position of needing to
           (perhaps as a result of needing to fix some existing Python 2 code or
           working with a technology that’s based on Python 2).

           Here are a few lines of Python 2 code that highlight some of the
           differences:


                                          In Python 3, the “raw_input()” function
                                          is called “input()”.




                               age = raw_input("How old are you? ")
                               if int(age) > 30:
                                      print "Sorry, but you’re past it!"
                               else:
                                      print "You still have hope ... for now!"
             Python 2 does
              not require the
              parentheses with
              the call to “print”,
              whereas Python 3
               does.


                                                                                      you are here 4    387
   417   418   419   420   421   422   423   424   425   426   427