Python Cookbook, 3rd Edition – Breaking Away from Python 2 to Python 3 – #programming #bookreview

Python Cookbook, 3rd Edition
David Beazley & Brian K. Jones
(O’Reilly – paperback, Kindle)

PYTHON 3 users will be very pleased with this new book. Those who still cling to Python 2 likely will not.

Even though “most working Python programmers continue to use Python 2 in production,” its authors concede, and “Python 3 is not backward compatible with past versions,” this third edition of the popular Python Cookbook is intended to be used only with Python 3.3 and above.

“Just as Python 3 is about the future, this edition…represents a major change over past editions,” Beazley and Jones state. “First and foremost, this is meant to be a very forward looking book. All of the recipes have been written and tested with Python 3.3 without regard to past Python versions or the ‘old way’ of doing things. In fact, many of the recipes will only work with Python 3.3 and above.”

THEIR “ultimate goal,” they point out, was “to write a book of recipes based on the most modern tools and idioms possible. It is hoped that the recipes can serve as a guide for people writing new code in Python 3 or those who hope to modernize existing code.”

The 687-page Python Cookbook, 3rd Edition is not intended for beginning programmers. However, beginners can learn a few things from it and keep the book on their shelves for future use as they gain experience with Python 3.

And, it can be a helpful guide if you are working to update some Python 2 code to Python 3. According to the authors, “many of the recipes aim to illustrate features that are new to Python 3 and more likely to be unknown to even experienced programmers using older versions.”

THE book offers 15 chapters of how-to recipes organized into the following major categories:

  1. Data Structures and Algorithms
  2. Strings and Text
  3. Numbers, Dates, and Times
  4. Iterators and Generators
  5. Files and I/O
  6. Data Encoding and Processing
  7. Functions
  8. Classes and Objects
  9. Metaprogramming
  10. Modules and Packages
  11. Network and Web Programming
  12. Concurrency
  13. Utility Scripting and Administration
  14. Testing, Debugging, and Exceptions
  15. C Extensions

Each of the approximately 260 recipes is presented using a “problem-solution-discussion” format. Here are a few recipe titles chosen at random:

  • “Combining and Concatenating Strings”
  • “Reformatting Text to a Fixed Number of Columns”
  • “Bypassing Filename Encoding”
  • “Iterating over the Index-Value Pairs of a Sequence”
  • “Capturing Variables in Anonymous Functions”
  • “Implementing Stateful Objects or State Machines”
  • “Enforcing an Argument Signature on *args and **kwargs”
  • “Creating Custom Exceptions”
  • “Writing a Simple C Extension Module”

SOME of the book’s code examples are complete. But others, the authors caution, “are often just skeletons that provide essential information for getting started, but which require the reader to do more research to fill in the details.”

If you are serious about Python and keeping pace with its progress, you should seriously consider getting this excellent how-to book.

Si Dunn

Python for Kids – A fun & efficient how-to book that even grownups can enjoy – #programming #bookreview

Python for Kids
Jason R. Briggs
(No Starch Press – paperback, Kindle)

Subtitled “A Playful Introduction to Programming,” Python for Kids is recommended “for kids aged 10+ (and their parents).”

But what if your kids are grown or you don’t have any kids? Should you ignore this book while learning Python? Absolutely not.

I’ve recently taken two Python 3 classes, and I wish I had had many of the explanations and illustrations in Python for Kids available to help me grasp some of the concepts. I’m keeping this book handy on my shelf for quick reference, right next to works such as Head First Python and Think Python.

Yeah, it contains plenty of silliness for kids, such as a wizard’s shopping list that includes “bear burp” and “slug butter,” and using if and elif statements to create jokes such as “What did the green grape say to the blue grape? Breathe! Breathe!” (I have grandchildren who consider this stuff uproariously funny.)

But Python for Kids also covers a lot of serious topics in its 316 pages and shows—simply and clearly—how to handle many major and minor aspects of the Python programming language. NOTE: This book is for the newer 3.X versions of Python, not older 2.X versions that are still in use and still a focus of some books for beginners.

One Python class I took didn’t introduce tuples until the 7th week of lectures. Python for Kids, however, has the reader using tuples on page 38, right after six pages of learning how to work with strings and lists. And the explanations and examples for these elements are clearer than what I got in a college-level course. (Of course, it helps when exercises involve “bear burp” and “gorilla belly-button lint” rather than boring generics such as “Mary has 3 oranges” and “Jack has 6 pencils.”)

Jason R. Brigg’s new book also shows how to draw shapes and patterns and create simple games and animations—topics not covered in some other beginning Python books I have used.

Another cool feature of this excellent how-to book is an afterword titled “Where to Go from Here.” It provides suggestions and gives links for those who want to learn more about games and graphics programming or take up other programming languages such as Ruby, PHP or JavaScript.

Bottom line, Python for Kids offers education and entertainment for children, their parents, and almost anyone else serious about having some fun while learning Python 3.

Si Dunn

Think Python – A gentle and effective guide to learning Python programming – #programming #bookreview

Think Python
Allen B. Downey
(O’Reilly, paperbackKindle)

First, a confession. My favorite book for learning Python is Head First Python by Paul Barry. It literally does throw you head-first into Python programming. By page 10, it has you working with nested lists. By page 30, you are creating a function that you will save and turn into a module just a few pages later. By the time you hit page 50, you have learned how to upload code to PyPi. And, as the book continues, you keep improving and expanding the functionality of one project that stays in development from chapter to chapter.

That said, I hereby declare that Think Python by Allen B. Downey is my new co-favorite book for learning Python.  I intend to keep it handy right alongside Head First Python.

Just about anyone studying or using Python can benefit from having Think Python on their bookshelf, in their computer, on their mobile device or, better yet, accessible in all these places. It is an excellent reference book, as well as a clear, concise and calm how-to guide for beginning programmers.

Think Python takes a gentle yet effective approach to introducing and exploring the language one step at a time. First you learn some basic programming concepts. Then, 13 pages in, you start easing into the language at the level of “Hello, World!”, plus variables, expressions, and statements.

The 277-page book has 19 chapters that carefully explain and illustrate each key point, without overkill. The author is a veteran instructor of computer languages, and he also is the author of a well-known book that has been around since 1999, in one form or another: How to Think Like a Computer Scientist.

Think Python is an outgrowth of the Python version that book. Downey has added materials on debugging and other topics, plus some exercises and case studies. And he has gotten plenty of proofreading help from more than 100 enthusiastic followers of his writings and teaching.

What I like most about Think Python are its short, concise, clear explanations of each new concept and its use of very short code examples. When I’m in the mood to spend just a few minutes reviewing or learning a new concept in Python, I can open Think Python and quickly find a refresher or a new area to try out. Head First Python, on the other hand, suits me best when I have an hour or two to stay focused on reading, keying in a lot more code and making the required changes to the ongoing project.

One minor caution: There are differences – sometimes significant and sometimes merely irritating – between Python 3 and Python 2. Head First Python focuses on Python 3 code and Think Python uses Python 2 code examples. But Think Python’s author has been careful to minimize the conflict and explains what to do when using Python 3.

The main thing to remember is that the print statement in Python 2 has become print(), a function, in Python 3. So if, for example, the book’s code says print ‘Hello, World!’ and you are using Python 3, you type print(‘Hello, World!’), instead.

It’s not hard. But the opportunity to print or print() something does come up a lot in the text.

Si Dunn