Skip to content

16 search results for "python"

Cracking Codes with Python

Cracking Codes with Python: An Introduction to Building and Breaking Ciphers has two goals. The book aims to teach the novice how to program in Python while also providing a good foundation in ciphers, encryption, and cryptography.

There is nothing in the book that will help the reader replace the excellent open source implementations currently available. That is not the goal. Rather, the reader has a chance to learn the foundations underlying classic and modern attempts to secure communication between parties.

The classics are all here, from simple reverse cipher and transposition all the way through to one-time pad ciphers and public key ciphers. The book starts simply from both a programming and a code perspective, gradually adding complexity while explaining first how a cipher works, then how it is coded, then what its weaknesses are and why you would want to move on to something better.

If learning Python while studying basic cryptography is of interest, you will find this book useful and well worth your time.

Disclosure: I was given my copy of this book by the publisher as a review copy. See also: Are All Book Reviews Positive?

Two Python Books

I like Python. I like its internal consistency. I like its design that all but ensures there is one right way to write almost anything and that any good Python programmer can figure that way out and use it. I have reviewed several Python-focused books and expect to do so in the future. So, this review will not be about the language itself, but about how well each of the two books included cover the language and provide interesting use cases.

There are two books in this review: Learn to Program with Minecraft: Transform Your World with the Power of Python and Python Crash Course.

and

Learn to Program with Minecraft: Transform Your World with the Power of Python presents a fun use case with Python. It covers how to install Minecraft, Python, Java, the Minecraft API, and a single-player Minecraft server called Spigot to allow you to take advantage of Python to do things to your Minecraft world. One thing to note is that installation is only covered on Windows and Mac OSX. The book also covers using the IDLE editor with Python, the Python shell, and all the basics of the language within the book-long use case of making modifications and improvements to your Minecraft world. Topics covered include variables, expressions, operators and basic mathematics, strings, booleans, if/then/else statements, loops, functions, lists and dictionaries, files and modules, and the basics of object-oriented programming. Good stuff. The text is presented with full-color examples and beautiful graphics throughout. The writing is clear and easy to follow.

Python Crash Course takes a different tack. The audience is similar, mainly young people who are just starting their coding journey. However, the approach is more generic in application and perhaps more detailed in what it covers. As with the other book, the examples are project-based, but not focused on interacting with one specific software product. You get all the same basics as the other book, but with extended coverage (to be fair, it has nearly double the page count). The projects in this book are interesting and cover a broader set of topics: you get multiple chapters each covering one game project, one data visualization project, and one web application. I also like that in this book Linux is covered alongside Windows and Mac OSX, although the Linux install examples use APT, wish presumes the use of Debian or Ubuntu or another Debian-derivative. Not a problem for me, but I would have liked to seen that called out.

I liked both of these books. If I was focused only on interacting with Minecraft and modifying my game, the first would be my preference. For all other use cases involving learning Python, the second book is superior and the one I recommend.

Disclosure: I was given my copy of this book by the publisher as a review copy.

Python for Kids

I previously reviewed a book intended to teach programming to kids, Super Scratch Programming Adventure. That book used a self-contained editor and language that was easy to understand, easy to use, but confined its usefulness to a very limited set of roles. This is because of how Scratch is run and written.

It is no secret that I like Python. Even though I really don’t write code anymore, at least not very often, for most purposes I am still a big fan of Python over any other programming language I have learned. I’ve reviewed two Python books in the past, Learning Python and Python for Unix and Linux System Administration. While I know people who use Python as a beginner’s language for kids, I had not done any reading nor read any curriculum used for teaching programming to kids using Python that I felt I could recommend freely. Until now.

Python for Kids: A Playful Introduction to Programming is by Jason R. Briggs. It is the book that fills the hole in my Python library. It starts with a nice introduction and installation instructions for Windows 7, Mac OS X, and most importantly to me, Ubuntu (on which you are really only checking to make sure you have Python 3 installed, since Python is installed by default, although Ubuntu releases older than 12.04 may still have Python 2.x installed as default). Perhaps it is because we started in a similar era, but I found Briggs very easy to read and follow; like me, he started out by learning BASIC on a TRS-80. More likely, the clarity and tone are the result of an intentional focus so that kids can comprehend the complexities of the material. In either case, he did a wonderful job.

The book is broken down into logical chapters, each building upon the previous ones. It starts with foundational concepts like variables and calculations, adds types like strings and lists and tuples, then begins with an introduction to graphic interaction using the turtle module. This is much sooner than typical, and I think it is beneficial because it gives kids a quicker jump to that fun moment of power, “Hey! I just made that thing move on the screen.”

Then the book builds understanding with explanations of if and else statements and loops. On top of that are added the concepts of functions, modules, classes, and objects. We are now a mere third of the way through the book.

From here on, the simple explanations given will be expanded upon in easily-absorbed chunks. Built-in Python functions and useful modules each get a chapter. Then, we revisit turtle graphics to play some more. Once the basic graphic concepts are taught with turtle, tkinter is presented.

The last third of the book is focused on games. Specifically, using some fun game examples to flesh out the concepts more completely, developing greater fluency with the concepts, grammar, and vocabulary already presented.

One weakness of many beginning programming books is that once you finish the book you have to do further research on your own to figure out what to do next. I love that Python for Kids does not end this way, but instead includes a useful Appendix titled Where to Go from Here. This Appendix is short, but gives enough information to help the reader learn just a little bit about some Python resources and other programming languages to make those next steps just a little bit easier.

This book is suitable for kids in upper elementary school and older. The only real prerequisites are the ability to read and understand the concepts and a computer that will run Python. While the book is clearly written using suitably simple vocabulary, it is not watered down and never talks down to the reader. For this reason, despite the title, this book could be just as useful for the adult programming novice, too.

Disclosure: I was given my copy of this book by the publisher as a review copy.

Learning Python, fourth edition

Years ago I purchased a copy of the very first edition of Learning Python.It was a small book, about 350 pages, but in 1999 when it came out, it was one of the best introductions to the language that existed. I hadn’t picked up my copy for some time, but I remember well how useful it was when I first bought it. When O’Reilly offered me a free review copy of Learning Python, fourth edition, I figured the differences between the two editions would primarily consist of updates to the content based on the differences in Python release versions, and that I wouldn’t likely learn much more from the new edition. I was wrong, and I will explain how and why below.

This book is HUGE. It weighs in at over 1100 pages and is filled with clear explanations, interesting history, and the most useful description of the foundations of the Python programming language that I have seen. The material was developed by the author, Mark Lutz, over the last decade, during which he has taught hundreds of seminars introducing Python. Lutz compiled the new edition based on the materials taught in a three day training class, complete with quizzes and meaningful exercises. While Lutz was one of the two original authors of the first edition, he is now the sole author of the book and it is obvious that his extensive experience teaching seminars has refined his presentation of Python in ways that will benefit readers of this book. The understanding of student needs shows clearly in the text, which focuses on the core of the language.

Learning Python is based on the new 3.x series of the Python language, but points out the differences between it and the still-supported and sometimes incompatible earlier 2.6 edition, so whichever version of the language you are learning or require you will find the information you need to begin here. Some may ask why cover the old version when the new one has so many improvements, but the answer is simply that there is a lot of legacy code that is not going to be updated soon and so people will need to support that code, which is often incompatible with Python 3.x without some changes.

The book covers many topics, none of which seem unimportant or superfluous. While the page counts seems quite daunting, a closer examination shows there is no need to be intimidated. The page count does not add complexity or difficulty, but actually gives room for clearer and more complete descriptions and definitions alongside practice questions that students will find very useful. The topics include all of the obvious foundational needs starting with history, how to run programs and use some common editors. It moves to core data types and operations, spending several pages clearly defining and describing each and how they are used, before introducing statements and syntax on page 261. I like how the differences between 2.6 and 3.x are clearly shown, such as the change from a print statement in 2.6 to a print function in 3.x and how either is implemented and used as well as the reasoning behind the change. Functions are introduced and discussed, as are modules, classes, object oriented programming, exceptions, and several advanced topics. There are two appendices covering installation and configuration and giving the solutions to the exercises in the book

It has been a long time since I did any programming. My life took a different path. This book has reminded me of how fun it is to write and read code in Python and made me wonder how I might find or create opportunities to return programming to my busy life (but this time around, if I make the time to write anything, it will be in Python 3.x). This book is why.

Lutz has also authored O’Reilly’s Programming Python, which was explicitly designed to be a follow up text to this one, which I have read and which also sits on my bookshelf, but which I have not reviewed (I bought that one a couple years ago and at the time was not writing book reviews.–if there is interest, I’ll review it at a later time).

Disclosures: I bought the first edition, but was given this fourth edition free by O’Reilly as a review copy, I also write for O’Reilly.

Python for Unix and Linux System Administration

I have four Python books on my shelf. I like the language, at least in theory. It is easy to read, clear, and powerful. In practice, I really don’t program much. I was hoping that this book might push me over the edge from writing shell and PHP scripts for my simple needs into Python land. So many of my friends love the language.

I read the book this week. There are a lot of great ideas in there that would be useful for a sysadmin. The examples chosen are generally practical and useful. I was a bit disappointed by the occasional typographical or capitalization error, especially in code examples and discussion, which are not uncommon in first edition books, but are generally uncommon from O’Reilly books. I also found the early emphasis on iPython to be a bit excessive.

This is a bit shorter than my usual review, mainly because I can’t think of much else to say about the text. It isn’t bad, but it isn’t great. A sysadmin who is motivated to use Python will find it useful as a foundation. A veteran Python programmer who wants to use the language for systems administration will probably find the book filled with stuff they could have figured out anyway. I wanted to love the book, but I didn’t. I didn’t hate the book, either. I just feel a bit “meh” about it.

Learn Java the Easy Way

This is an enjoyable introduction to programming in Java by an author I have enjoyed in the past.

Learn Java the Easy Way: A Hands-On Introduction to Programming was written by Dr. Bryson Payne. I previously reviewed his book Teach Your Kids to Code, which is Python-based.

Learn Java the Easy Way covers all the topics one would expect, from development IDEs (it focuses heavily on Eclipse and Android Studio, which are both reasonable, solid choices) to debugging. In between, the reader receives clear explanations of how to perform calculations, manipulate text strings, use conditions and loops, create functions, along with solid and easy-to-understand definitions of important concepts like classes, objects, and methods.

Java is taught systematically, starting with simple and moving to complex. We first create a simple command-line game, then we create a GUI for it, then we make it into an Android app, then we add menus and preference options, and so on. Along the way, new games and enhancement options are explored, some in detail and some in end-of-chapter exercises designed to give more confident or advancing students ideas for pushing themselves further than the book’s content. I like that.

Side note: I was pleasantly amused to discover that the first program in the book is the same as one that I originally wrote in 1986 on a first-generation Casio graphing calculator, so I would have something to kill time when class lectures got boring.

The pace of the book is good. Just as I began to feel done with a topic, the author moved to something new. I never felt like details were skipped and I also never felt like we were bogged down with too much detail, beyond what is needed for the current lesson. The author has taught computer science and programming for nearly 20 years, and it shows.

Bottom line: if you want to learn Java, this is a good introduction that is clearly written and will give you a nice foundation upon which you can build.

Disclosure: I was given my copy of this book by the publisher as a review copy. See also: Are All Book Reviews Positive?

Teach Your Kids to Code

Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming is a unique and welcome addition to the recent trend of programming books with a focus on teaching children. Unlike books that are designed for self-study, Teach Your Kids to Code is intended to be used in a collaboration between an adult and a child. This could be a parent working with a daughter or son or a teacher working with one or more students. It certainly could be used for self-study, but I like how the intent and focus is to provide something to do together.

The book covers all the important topics from installing and setting up Python on your platform to creating a game. In between, we are treated to coverage of drawing graphics, first simply using Turtle in Python, and later with animated effects using Pygame. Concepts like math, numbers, and variables; loops; conditions; functions; and user interaction are covered clearly and in a logical order within an interesting and enjoyable context.

Each chapter ends with a set of programming challenges to give the readers a way to practice what was learned in the chapter. Sample answers are made available on the publisher’s website. These are interesting and valuable.

I really like this book. If you are an adult looking for a fun project to do with a child in your life, or a kid looking for a way to interest an adult in learning how to use Python, Teach Your Kids to Code is worth a close look.

Disclosure: I was given my copy of this book by the publisher as a review copy. See also: Are All Book Reviews Positive?

Super Scratch Programming Adventure!

My parents bought my first computer for me in 1981. I was 11. When my TRS-80 Color Computer was turned on, it booted up into a BASIC editor. What it did afterward was up to me. That computer came with a whopping 4K (not a typo, K) of RAM and no storage. We bought a cable to connect the computer to a cassette tape deck so that I could store programs on cassettes. It took several minutes to load an entire program into memory.

I’m feeling nostalgic, but this article is not about that computer. It is about learning to program as a kid. I learned BASIC because I didn’t know anything else existed. I had this cool machine and I wanted to bend it to my will, to make it do my bidding. It started with simple things like accepting text input and repeating it on the screen. Later I learned how to save a Christmas card list and print it using an early dot matrix printers, the DMP-100, which had a really amazing 5×7 matrix (which meant no true descending characters, those ys and gs and stuff all got moved up and looked weird…sorry, feeling nostalgic again).

Super Scratch Programming Adventure! provides a much easier and extremely fun entry into programming. It doesn’t make the learner focus on the really gritty details, like people in my generation had to do. That’s okay. What it does do is give kids a way to do the parts that I loved about owning a computer in the early 1980s, it gives them a chance to bend it to their will, to make the computer do what they want it to do.

I have three kids, ages 6, 9, and 10. Each of them has read this book. Each of them enjoyed the clever comic narrative that introduces each chapter. Each of them, even the youngest, found the book enjoyable and interesting as well as easy to understand and follow. The software used for programming, Scratch, is freely available from MIT, where it was created, and runs on several platforms including our family’s beloved Ubuntu. I installed it on their computer and off they went. They haven’t finished the book or the exercises yet, but they are doing what I did as a kid, having fun with a powerful toy that they can control.

The meat of the book is impressive. It covers some deep topics but always remains readable and clear for those within its target audience, which according to a note on the back cover is “for ages 8 and up.” I admit it, my 6 year old is advanced <grin>. The book leads the reader through the process of creating games in Scratch. Along the way, you learn about graphics, data flow, sound effects, subroutines, and more. This is done using an interface that is menu driven and easy. The concepts are what are focused upon, not the semantics. This is good, because I’ve known too many programmers who are good at semantics and yet struggle to know when or why certain things are done. I prefer to see the “why” understood first, then the “how” is easily transferred to other languages and contexts.

I’ve given away other programming books to kids, like the time a few years ago when I gave my nephew a book on game programming in Python. Starting now, this will be the book I recommend or give away to kids (to be followed later with Python or other stuff…). If you know a kid or even a young teen who wants to make their computer do stuff, this is a good start.

Disclosure: I was given my copy of this book by the publisher as a review copy.

Nginx HTTP Server

I started using Nginx as my primary web server a little over 18 months ago. At the time, I was using an underpowered server with low memory, and I wanted to replace Apache with something lighter. Even though I still love Apache for its power, configurability, and contributions to the open source world, there are times when other options are called for.

Nginx is an http server written in Russia intended for high traffic websites with a mind toward network scalability. It also works great as a lightweight replacement for Apache on my little server with 256MB RAM and one processor (that has since been upgraded, but I didn’t switch back). Even the day I had a post on the front page of of a popular social networking website, my little server withstood the onslaught without crashing.

The hard part of making the switch was finding documentation. As Nginx was birthed in Russia, I presume good documentation may be found in Russian, but since I don’t know the language that doesn’t help me. Finding documentation in English was a chore. Simple things were available at the main Nginx website and wiki (which have also grown and improved over time), but I had a difficult time finding detailed information about specific things I needed, such as translating Apache 301 rewrite rules into a format that would work in Nginx so that I could continue to use WordPress with pretty URLs.

Nginx HTTP Server is the first English book I have seen that compiles quality documentation and instruction for using Nginx. The information is current, detailed, and clear.

Some of the topics in the book seem to me to be a bit odd. There is a whole chapter dedicated to basic Linux shell commands and administration. Perhaps this will be useful for some, but I would imagine most people interested in Nginx will already know the topic. The second chapter discusses downloading source code, configuring, and installing the traditional way along with writing up a SysV init script for the service. I think that is good information to include. Strangely missing is information about installing Nginx from Linux distribution repositories, which is far easier, especially for the presumed newbies who needed the first chapter on shell commands.

The real value of this book is in chapters 3 – 8. Here we dive deep into configuration options, file syntax, modules, variables  and more. We learn how to set up PHP and Python with Nginx, which will make hosting most popular website software like WordPress, vBulletin, or anything built with Django fairly simple. Also discussed are similar methods of enabling other languages and platforms like Perl or Ruby on Rails.

The last two chapters are great for people coming over from Apache. One discusses how to use Nginx as a front end proxy to speed up a website running Apache. The other discusses how to make a full switch. Both include great comparisons and honest discussions of the strengths and differences between Apache and Nginx, including some good advice about when one may be a better choice than the other.

I have a lot of good things to say about this book, and I’m glad it exists. It will remain on my shelf as a useful reference for specific modules and configuration details that are not committed to memory. Comparing its contents to what I already know of Nginx, I believe the book to be technically accurate and current.

The book does have one glaring weakness, though. The quality of the writing is inconsistent. Most of the time, the text is adequately clear and communicates well. However, there is an annoying tendency throughout the book toward awkward grammar and odd phrasing, perhaps as often as one occurrence every two or three pages. This tells me two things: the book was probably written by someone who is not a native English speaker, which is not a big deal at all, and that the copy editing and proofreading was weak, which is a major failing. The initial cringe-worthy portion occurs in the very first paragraph of the Preface:

…for the past few month the same reports reveal the rise of a new competitor: Nginx, a lightweight HTTP server originating from Russia–pronounced “engine X”. There have been many interrogations surrounding the pronounced newborn. Why has the blogosphere become so effervescent about it?

Packt Publishing generally releases books on technology that are current and contain accurate information. The company focuses their efforts on very narrow, niche topics that they alone offer, and I like that. They also have a disappointing habit of being filled with this sort of writing. This book is no exception. Since, like many of their offerings, this is the only book on a topic that is interesting and useful to a specific group of people, I can’t help but recommend that people using or wanting to use Nginx take a look at the book. Still, I would love to see the language of their books rise to the level of their technical content. This would allow me a clearer conscience in recommending their products.
Disclosures: I was given my copy of Nginx HTTP Server free by Packt Publishing as a review copy. I am also a professional writer for a software project and have written for magazines, websites, and books for both O’Reilly Media and Pearson Education (both Prentice-Hall and Sams).

Regular Expressions Cookbook and Mastering Regular Expressions

I have a copy of Mastering Regular Expressions by Jeffrey E. F. Friedl on my bookshelf. I bought it a long time ago to try to improve my skills at using regular expressions to search text and check input against desired norms. While that book is clear and well written, I am sometimes a bit impatient and it was taking too long for me to figure out how to do the things I wanted to do and I got distracted or busy before I read enough to complete the task (I ended up using Google and finding what I needed quickly). I have to admit that I still don’t have the regular expression skills I want to have, although this book promises to teach them to me. Someday it may do so.

When I heard that O’Reilly had an upcoming regular expressions offering to add to their Cookbook series, I was interested, but was finishing up my own title in the series. Once my task was finished, I talked to some friends at the publisher and they kindly sent me a review copy of Regular Expressions Cookbook by Jan Goyvaerts and Steven Levithan. Now that I have had time to read through the book, I can say that it exceeds my expectations and hopes.

What I was looking for was a book that would teach regular expressions while giving concrete examples of real life use cases that I could immediately put to work. This book is filled with them.

Chapters one and two lay the foundation by covering the basics of what regular expressions are, using them to search and replace, match text, and other basic skills. This is good, but where the book really sets itself apart is in chapters three through eight, which are overflowing with useful recipes for things like validating ISBNs, finding URLs within text, stripping leading zeros or matching IP addresses (IPv4 and IPv6). The book has an obvious organization scheme, a ton of useful recipes, and a useful index. Finding what you want or need is very easy to do, and unless your needs are especially unique or esoteric, you will probably discover exactly what you require in the book.

The best part of the book is that every example uses a clear format that sets the stage for an easy discovery of needed information.

First, a problem is stated, such as in chapter four’s item, 4.1 Validate Email Addresses, which says, “You have a form on your website or a dialog box in your application that asks the user for an email address. You want to use a regular expression to validate this email address before trying to send email to it. This reduces the number of emails returned to you as undeliverable.”

Next, a solution is defined, with code examples, accompanied by a description of the particular details that are vital to comprehend when implementing the solution. Next, each recipe has a section for further discussion that leads to a deeper understanding of the regular expression being used and the context in which it is being used.

Especially wonderful is that every recipe has very specific and clear code examples for use with Perl, PCRE (the “Perl Compatible Regular Expressions” library for C, which isn’t identical to Perl’s use of regular expressions, even though it tries), .NET, Java, JavaScript, Python, PHP, and Ruby with notes on which specific release versions or variations of each are covered. When differences exist in the implementation in these environments, those differences are clearly noted and discussed. This feature will make life much easier for people who need to use regular expressions in more than one language context and is a feature of the book I appreciate greatly.

The other regex book on my shelf will remain there until that mystical moment “when I have time to study it.” This book will be used regularly as a reference.

Disclosures: I bought my copy of Mastering Regular Expressions, but was given my copy of Regular Expressions Cookbook free by O’Reilly as a review copy, I also write for O’Reilly and have a book in their Cookbook series.