Beginners Python Books
I recently found my self with some time to kill (you don’t have to watch the Tour De France that closely) and as I had a Python for QGIS course coming up for the first time in a year I thought I could use some revision. I’m not a “native” python writer (lack of types while liberating is also scary to a Java boy like me), so brushing up on my Python seemed like a good idea. I had recently bought two new Python books from Manning. Tiny Python Projects by Ken Youens-Clark and Python Workout by Reuven M. Lerner and this was an ideal opportunity to read through them.
Tiny Python Projects
Tiny Python Projects comes as a series of 22 chapters where you build a new program against a set of unit tests that the author provides via a git repository. They start off simple hello world program and building through strings, lists and dictionaries. Then adding functions (and testing functions) to algorithms and regular expressions to finish up with a working tic-tac-toe (noughts and crosses) game. I found this book great fun to read and in the later chapters to code along to as well. The emphasis on test driven development is, I think, a really useful process for new programmers to get used to. All to often I see students (and others) who write some code and hope that it works but often never check it (in some cases ever). If I’ve learnt anything in the 30 odd years I’ve been coding it’s that with out a test that code is worthless, if only because when you come back to it the test will remind you how to run it if nothing else. One of the things that seems to upset new contributors to GeoServer and GeoTools is our insistence on a test case before we start to look into their issue, the trouble is that with no test how can we know if we fixed your problem. So any book which helps to instil this understanding of the necessity of testing in new coders is great.
The topics covered a wide ranging and while often silly (e.g. spotting animals from the crows nest) they cover a good depth of python topics and I think a new python programmer could easily teach themselves how to produce complex (and correct) programs to could do useful work from this book. If you plan to go on to use Python in a specific domain then there would almost certainly be new modules and packages that you would want to explore and learn but this book would give you the grounding that you’d need to understand the documentation and examples that this would lead to.
Python Workout’s subtitle is 50 ten-minute exercises, and this gives you a flavour of the book’s contents. As it sounds each chapter is a single exercise with discussion on the “best” solution and why it is in the author’s opinion the best way of solving it. There are also videos of the author solving each problem which some might find useful as it does give an insight into the way that the solution is developed. Most of the chapters also provide a link to Python Tutor which allows you to step through some python code and see what happens as each line is executed. This tool is new to me but I think I will be looking at adding it to my teaching in the future.
Again the topics covered in Python Workout start at simple numbers, strings, lists, dictionaries before more complex functions, functional programming with comprehensions, modules and packages and finishing up with creating your own iterators and generators. There is something here for everyone from beginners to experienced python programmers, and it is all nicely packaged up to give you a daily workout. The style is less formal that Tiny Python Projects with less emphasis on writing tests to make sure you have solved the problem but with more discussion on how to approach solving the problem.
Both of these books would be a great introduction to python to new programmers, and for programmers who are converting from another language. They provide a clear introduction to the language and the features that make python different from (or the same as) other languages, and take you through to the complex features that make programming with python fun (and challenging).
At first sight the books might seem expensive but Manning produce very nice well made physical and electronic books and you get the source code too. If you by the physical book you get the e-book for free where ever you buy it so you can save on shipping by ordering it locally. Also if it looks expensive today, wait a day or two and Manning will almost certainly be having a 40% off sale, or a buy one get one free week or some other deal, I don’t think I have ever paid full price for one of their books.