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

Big Data Book Blast: Hadoop, Hive…and Python??? – #programming #bookreview

Big Data is hothotHOT. And O’Reilly recently has added three new books of potential interest to Big Data workers, as well as those hoping to join their ranks.

Hadoop, Hive and–surprise!—Python are just a few of the hot tools you may encounter in the rapidly expanding sea of data now being gathered, explored, stored, and manipulated by companies, organizations, institutions, governments, and individuals around the planet. Here are the books:

Hadoop Operations
Eric Sammer
(O’Reilly, paperbackKindle)

“Companies are storing more data from more sources in more formats than ever before,” writes Eric Sammer, a Hadoop expert who is principal solution architect at Cloudera. But gathering and stockpiling data is only “one half of the equation,” he adds. “Processing that data to produce information is fundamental to the daily operations of every modern business.”

Enter Apache Hadoop, a “pragmatic, cost-effective, scalable infrastructure” that increasingly is being used to develop Big Data applications for storing and processing information.

“Made up of a distributed filesystem called the Hadoop Distributed Filesystem (HDFS) and a computation layer that implements a processing paradigm called MapReduce, Hadoop is an open source, batch data processing system for enormous amounts of data. We live in a flawed world, and Hadoop is designed to survive in it by not only tolerating hardware and software failures, but also treating them as first-class conditions that happen regularly.”

Sammer adds: “Hadoop uses a cluster of plain old commodity servers with no specialized hardware or network infrastructure to form a single, logical, storage and compute platform, or cluster, that can be shared by multiple individuals or groups. Computation in Hadoop MapReduce is performed in parallel, automatically, with a simple abstraction for developers that obviates complex synchronization and network programming. Unlike many other distributed data processing systems, Hadoop runs the user-provided processing logic on the machine where the data lives rather than dragging the data across the network; a huge win for performance.”

Sammer’s new, 282-page book is well written and focuses on running Hadoop in production, including planning its use, installing it, configuring the system and providing ongoing maintenance. He also shows “what works, as demonstrated in crucial deployments.”

If you’re new to Hadoop or still getting a handle on it, you need Hadoop Operations. And even if you’re now an “old” hand at Hadoop, you likely can learn new things from this book. “It’s an extremely exciting time to get into Apache Hadoop,” Sammer states.

Programming Hive
Eric Capriolo, Dean Wampler, and Jason Rutherglen
(O’Reilly, paperback Kindle)

“Hive,” the three authors point out, “provides an SQL dialect, called Hive Query Language (abbreviated HiveQL or just HQL), for querying data stored in a Hadoop cluster.”

They add: “Hive is most suited for data warehouse applications, where relatively static data is analyzed, fast response times are not required, and when data is not changing rapidly.”

Their well-structured and well-written book shows how to install and test Hadoop and Hive on a personal workstation – “a convenient way to learn and experiment with Hadoop.” Then it shows “how to configure Hive for use on Hadoop clusters.”

They also provide a brief overview of Hadoop and MapReduce before diving into Hive’s command-line interface (CLI) and introductory aspects such as how to embed lines of comments in Hive v0.80 and later.

From there, the book flows smoothly into HiveQL and how to use its SQL dialect to query, summarize, and analyze large datasets that Hadoop has stored in its distributed filesystem.

User documentation for Hive and Hadoop has been sparse, so Programming Hive definitely fills a solid need. Significantly, the final chapter presents several “Case Study Examples from the User Trenches” where real companies explain how they have used Hive to solve some very challenging problems involving Big Data.

Python for Data Analysis
Wes McKinney
(O’Reilly, paperbackKindle)

No, Python is not the first language many people think of when picturing large data analysis projects. For one thing, it’s an interpreted language, so Python code runs a lot slower than code written in compiled programming languages such as C++ or Java.

Also, the author concedes, “Python is not an ideal language for highly concurrent, multithreaded applications, particularly applications with many CPU-bound threads.” The software’s global interpreter lock (GIL) “prevents the interpreter from executing more than one Python bytecode instruction at a time.”

Thus, Python will not soon be challenging Hadoop to a Big Data petabyte speed duel.

On the other hand, Python is reasonably easy to learn, and it has strong and widespread support within the scientific and academic communities, where a lot of data must get crunched at a reasonable clip, if not at blinding speed.

And Wes McKinney is the main author of pandas, Python’s increasingly popular open source library for data analysis. It (pandas) is “designed to make working with structured data fast, easy, and expressive.”

His book makes a good case for using Python in at least some Big Data situations. “In recent years,” he states, “Python’s improved library support (primarily pandas) has made it a strong alternative for data manipulation tasks. Combined with Python’s strength in general purpose programming, it is an excellent choice as a single language for building data-centric applications.”

Much of this well-written, well-illustrated book “focuses on high-performance array-based computing tools for working with large data sets.” It uses a case-study-examples approach to demonstrate how to tackle a wide range of data analysis problems, using Python libraries that include pandas, NumPy, matplotlib, and IPython, “the component in the standard scientific Python toolset that ties everything together.”

By the way, if you have never programmed in Python, check out the end of McKinney’s book. An appendix titled “Python Language Essentials” gives a good overview of the language, with a specific bias toward “processing and manipulating structured and unstructured data.”

If you do scientific, academic, or business computing and need to crunch and visualize a lot of data, definitely check out Python for Data Analysis.

You may be pleasantly surprised at how well and how easily Python and its data-analysis libraries can do the job.

Si Dunn

Practical Computer Vision with SimpleCV – ‘Seeing’ with Python – #programming #bookreview

Practical Computer Vision with SimpleCV
Kurt Demaagd, Anthony Oliver, Nathan Oostendorp, and Katherine Scott
(O’Reilly, paperbackKindle)

SimpleCV, or Simple Computer Vision, is “an easy-to-use Python framework that bundles together open source computer vision libraries and algorithms for solving problems,” according to the authors of this useful and informative how-to book.

The subtitle is “Making Computers See in Python,” and the codes examples require Python 2.7.

Why learn computer vision? “As cameras are becoming standard PC hardware and a required feature of mobile devices, computer vision is moving from a niche tool to an increasingly common tool for a diverse range of applications,” the authors note.

Indeed, cameras and computer vision now are being used in everything from facial recognition systems and video games to automobile safety, industrial automation, medicine, planetary exploration, and even agriculture.

“The SimpleCV framework has compiled installers for Windows, Mac, and Ubuntu Linux, but it can be used on any system on which Python and OpenCV can be built,” the authors state.

Practical Computer Vision with SimpleCV shows how to use the framework and simple application examples to get started toward building your own computer vision applications. The 240-page book has 10 chapters:

  • Introduction
  • Getting to Know the SimpleCV Framework
  • Image Sources
  • Pixels and Images
  • The Impact of Light
  • Image Arithmetic
  • Drawing on Images
  • Basic Feature Detection
  • FeatureSet Manipulation
  • Advanced Features (focuses on optical flow)

The book also has three appendices: Advanced Shell Tips, Cameras and Lenses; and Advanced Features (deals with advanced segmentation and feature extraction tools).

Practical Computer Vision with SimpleCV provides a good overview of computer vision basics and shows, using simple but effective examples, how you can put them to work.

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

PayPal APIs: Up and Running – How to monetize your apps – #programming #bookreview #in

PayPal APIs: Up and Running, 2nd Edition
Matthew A. Russell
paperback, list price $29.99; Kindle edition, list price $23.99)

The focus of this book is “monetizing your application with payment flows.” That’s a high-toned way of saying Click here to spend some money or Click here to pay your bill or Click here to donate.

PayPal APIs: Up and Running, 2nd Edition shows how to work with PayPal’s platform, which “offers a vast number of API-based products that allow you to monetize your ideas as seamlessly as possible.” (APIs are application programming interfaces.) The book is written clearly and is well illustrated with diagrams, code examples, screen shots and tables.

According to the author, PayPal’s Name-Value Pair (NVP) Application Programming Interfaces (APIs) make it “simple to integrate payments into your applications.  As the merchant, your web application constructs an NVP string and transmit(s) it via HTTPS (HTTP Secure) to the PayPal authorization server, and PayPal sends back an NVP-formatted response that your web application parses for the information relevant to the payment.”

What Matthew A. Russell’s book does not do is “provide complete or exhaustive documentation on all of PayPal’s products or even provide very specific direction on handling some of the most common idiosyncrasies that you might encounter.” But it does “aim to present some of the most popular products in fully integrated realistic scenarios with sample project code that you can study and adapt for your particular needs.” It shows you how to get started and points you toward sources of more advanced information.

Rather than introduce a new, “distinct sample application” in each chapter, the author’s approach is to use a single, simple application “as a foundation,” and “customize it in various ways according to the content of each chapter….” And the chapters are structured to be mostly standalone.

Early in the opening chapter, the foundation application is built using Python and Google App Engine (GAE). And you begin working with PayPal’s APIs.

The 135-page book is organized as follows:

  • Chapter 1: PayPal API Overview
  • Chapter 2: Express Checkout (Including Mobile Express Checkout)
  • Chapter 3: Express Checkout for Digital Goods
  • Chapter 4: Adaptive Payments (Simple, Parallel, and Chained Payments)
  • Chapter 5: Website Payments Pro (Direct Payment)
  • Chapter 6: Instant Payment Notifications (IPNs)
  • Appendix A: Overview of Tweet Relevance – Tweet Relevance is the book’s sample application, “implemented in Python (one of the easiest-to-read programming languages), runs on Google App Engine (a web application platform that is mature and extremely well documented), and munges data from Twitter (an accessible and extremely rich source of information),” Russell writes.
  • Appendix B: Mobile Payment Libraries (MPLs) – Goes beyond the scope of this book. Contains brief information on PayPal’s MPLs, including creating “in-app purchases for iOS, Android, and BlackBerry,” and gives guidance for finding more information.

Each chapter also contains recommended exercises, and the book’s code examples are available online.

The first edition of PayPal APIs: Up and Running was written by Michael Balderas. PayPal APIs: Up and Running, 2nd Edition builds upon his foundation and covers some new aspects and products of PayPal.

If you are a programmer who wants to accept payments for goods or services through PayPal or help a client accept online payments or donations, you should consider getting this useful and well-focused book.

— Si Dunn


Think Complexity – Exploring Complexity Science with Python – #programming #bookreview

Think Complexity
By Allen B. Downey
(O’Reilly, paperback, list price $29.99)

Are you a reasonably competent Python programmer yearning for new mental challenges? Allen B. Downey’s Think Complexity definitely can deliver some. His well-written new book can help you dive into complexity science and improve your Python skills at the same time.

Right away, you will see that Think Complexity is not just another how-to-program-in-Python book.

“This book,” Downey states, “is about data structures and algorithms, intermediate programming in Python, computational modeling, and the philosophy of science.” Hello, new world.

His new work, he adds, sprang out of a blending of “boredom and fascination: boredom with the usual presentation of data structures and algorithms and fascination with complex systems. The problem with data structures is that they are often taught without a motivating context; the problem with complexity science is that it usually is not taught at all.”

Complexity science is the scientific study of complex systems – which can be anything from computer networks to the human brain, global markets, ecosystems, metropolitan areas, space shuttles, ant trails, and countless other “systems.”

Complexity science is practiced “at the intersection of mathematics, computer science, and natural science,” Downey says.

How does “the philosophy of science” fit in? Downey’s book offers “experiments and results [that] raise questions relevant to the philosophy of science, including the nature of scientific laws, theory choice, realism and instrumentalism, holism and reductionism, and epistemology.”

Think Complexity “picks up where Think Python left off” and is intended to appeal to the “broad intellectual curiosity” of software engineers and their “drive to expand their knowledge and skills.”

There are case studies, exercises, code samples and even mini-lessons within the exercises. One brief example: “Hoisting is a way to speed up code by moving an expression that does not change out of a loop.” (Hoisting then is applied in a discussion involving Fast Fourier Transform and the Danielson-Lanczos Lemma.)

Not every exercise has an answer against which you can check your work. So you probably shouldn’t jump into this book just now unless you feel confident you are an intermediate-level Python programmer and you are open to wide-ranging mental challenges.

Python, by the way, is a free download available in 2.X and 3.X versions. And, along with Think Python, several other books can help you advance from novice to Python professional.

Head First Python by Paul Barry is a fun, “brain-friendly guide” nicely tailored for beginners who want to advance from “What’s Python?” to understanding how to use the language in real-world applications. The book is written for 3.X versions. And it uses multiple learning methods (often in amusing ways) to help impart the necessary how-to information.

Once you gain a basic understanding of Python, Mark Lutz’s book Learning Python is recommended as the next step. His 4th edition covers both the 2.6 and 3.X versions. If you are a complete Python beginner, you might want to put this book second on your list, rather than dive into it from a cold start. It has 39 chapters and 1162 pages, and it weighs nearly four pounds – which can make it seem a very intimidating starting point. Still, it is a well-written, self-paced tutorial, and it can help you advance to intermediate-level Python programmer and beyond.

Students at Olin College (where Allen B. Downey is a computer science professor) wrote the case studies for Think Complexity. (They were edited by Downey and his wife and reviewed by other Olin faculty members). Appendix A of Downey’s new book contains a call for readers to submit additional case studies.

“Reports that meet the criteria [explained in the appendix] will be published in an online supplement to this book, and the best of them will be included in future print editions.”

This may be an offer – and a Python challenge — you can’t refuse.


Si Dunn is a novelist, screenwriter, freelance book reviewer, and former software technical writer and software/hardware QA test specialist. He also is a former newspaper and magazine photojournalist. His latest book is Dark Signals, a Vietnam War memoir available now in paperback. He is the author of a detective novel, Erwin’s Law, a novella, Jump, and several other books and short stories.