Python 101

Author: Michael Driscoll
Publisher: Michael Driscoll
Pages: 238
ISBN: 978-0996062817
Audience: New and not so new users of Python
Rating: 4
Reviewer: Sue Gee

Python has become a popular language for beginners. Is this book a good way to get started?

 

If the name Michael Driscoll sounds familiar it is because he has a Python Blog and he has contributed reviews of Python books to I Programmer.

He has written Python 101 in response to many requests from readers of his blog and in a “blogging style” which means that it has forty four short chapters, each covering a specific topic.

Although the Introduction outlines four parts, the book actually has five. This reflects the fact that its preparation was fund by a Kickstarter which reached a stretch goal of adding some intermediate material. So what Mike Driscoll has produced is a beginner's book that takes you a step further towards mastery of Python.

The five parts are:

  1. Learning the Basics
  2. Learning from the Library
  3. Intermediate Odds and Ends
  4. Tips, Tricks and Tutorials
  5. Packaging and Distribution

 

and of these it is Part III that is the extra one.

 

Banner

 

A very brief history of Python is included in the Introduction and Chapter 1 introduces IDLE, Python's code editor, which while not a full IDE (integrated development environment) has helpful features. I think this is a good place to start as it will encourage readers to work through rather than simply read this book.

This is essentially a hands-on introduction to Python and not a book to curl up with or read on your commute. There is enough of information for you to follow it with typing everything in – but if you are a beginner actually entering and running the snippets of code will make it stick all the quicker.

 

The first Python topic to be covered in Chapter 2, is Strings. This is followed up in Chapter 3 with Lists, Tuples and Dictionaries. Chapter 4 moves onto Conditional Statements, introducing the if/elif/else structure, Boolean operations, and the use of False. It also covers the use of some special characters that occur in strings and can cause problems, This indicates a problem all authors have to face – how to maintain a logical structure without getting too complicated at the very start without omitting details that are going to trip up the novice coder.

 

Chapter 5 is on Loops and we are back on a logical course with the for loop and the while loop. Chapter 6 builds on your knowledge of loops and conditionals to tackle Python comprehensions, which are used to create various types of sets – lists, dictionary set.

 

Chapter 7 is on Exception Handling. Whether its a bit early to be introducing this is debatable – but once you start to write code bad things can happen so knowing about common types of errors and how to deal with them, using try/except is a good idea.

 

Chapter 8 is straightforward as it covers reading and writing data to and from files but Chapter 9 is on importing module and is rather confusing. It starts off demonstrating what happens when you use import this – and instead of importing anything you get an unexpected item, explained as an Easter Egg – a common computing expression for surprises. The math module is used as something that can be imported and then pi and sqrt as functions from the math module that can be imported individually.

 

It is a bit surprising that this is the first time we've encountered any arithmetic, which is often the starting point for a beginner's book on a programming language because of the close association between computing with numeric computation. However now we have met functions in the context of modules and Chapter 10, which is devoted to the topic of Functions includes thee add function when introducing the idea of arguments.

 

Part I of the book finishes with Chapter 11 on the topic of Classes and tries to do this without a full explanation of object-oriented programming. Introducing classes at this point is necessary because the rest of the book makes the assumption you know about them, but it is a jump in level.

 

 

One of the reasons why Python has become so widely adopted, or perhaps as a consequence of its widespread use, is its extensive library of modules that provide it with added functionality. Part II provides reference material for a selection of these modules but starts with a chapter the idea of using Python to figure out Python. With the title “Introspection”, Chapter 12 covers the type and dir functions and the help utility. With these three you can find out a lot about any module.

The modules in the rest of Part II are:

  • csv for parsing comma separated value files (Chapter 13)
  • configparser (Chapter 14)
  • logging  which can be used as an alternative to debugging (Chapter 15)
  • os (Chapter 16)
  • email and smptlib (Chapter 17)
  • SQLlite (Chapter 18)
  • subprocess (Chapter 19)
  • sys (Chapter 20)
  • threading (Chapter 21)
  • datetime and time (Chapter 22)
  • xml (Chapter 23)

The intermediate material in Part III kicks off with a look at the Python debugger, pdb. After explaining how to start the debugger it shows how to step through code and set breakpoints. The other chapters in this part are on decorators, lamda, properties, debugging, profiling and testing.

Many readers will leave Part III until later on and go straight to Part IV. It opens with a chapter on installing third party modules. It introduces easy_install, but as this requires setuptools it first goes through how to install this prerequisite first. The chapter also covers pip – which is included in Python 3.4 but has to be installed manually in other versions. The advantage of using either easy_install or pip, it explained – namely that they attempt to download and install any packages specified as dependencies by the package you are interested in.

 

Chapter 30 is on ConfigObj a third party configuration module that is an improvement over ConfigParser that is part of the Python standard library. A third party XML parser, lxml comes next and hten we move on to Python Code Analysis using pyflakesand then there's a very short chapter on the requests package, an alternative for Python's onw urlib. Chapter 34 is a self-contained tutorial on using SQLAlchemy, an Object Relational Mapper, to create a database. The final chapter in this part is again short and gives instructions for creating a virtual environment as a sandbox for testing purposes.

 

In the final part we learn about creating out own modules or packages and sharing them with other on the Python Package Index (PyPI) or as a Python egg or a Python wheel. This sounds complicated and outside the scope of a beginner book, but Mike Driscoll walks us through creating a simple math module and then converting it to a package in Chapter 36.

In Chapter 37 we learn how to publish the mymath package just created on PyPI and in the next two chapters we are shown two alternatives for distribution – the older format that is basically a zip file with the extension .egg and the newer .whl format. From here we encounter py2exe, bbfreeze, cx_fgreeze and PyInstaller. Then in the final chapter we are walked through the process of creating an executable and packaging it into an installer.

 

This isn't the end of the book however. There is also an Appendix called Putting It All Together that goes from specification of a problem and looks at developing a complete program to deliver the required product. Interestingly the example chosen is the production of the book itself in a form that could be emailed as a pdf to all its subscribers.

 

So does Mike Driscoll's novel approach to introducing Python to beginner's succeed? I think the answer to this is yes as long as you actively work through the parts you are interested in.

On the whole it is likely to suit best those who have already gained some familiarity with Python and Computer Science in general from say a MOOC or those who have encountered another programming language. The extra material means that an intermediate Python program will find useful stuff included.

You can purchase the e-book from http://www.blog.pythonlibrary.org/buy-the-book/ in PDF. MOBI and EPUB versions plus a PRF copy in A4 size. You can also buy a printed version via that link or buy from Amazon.

 

 

Banner


Head First C

Author: David Giffiths & Dawn Griffiths
Publisher: O'Reilly
Pages: 591
ISBN: 978-1449399917
Aimed at: Beginner
Rating: 4.5
Pros: Good concept coverage, real life lab projects make it fun
Cons: Very UNIX oriented
Reviewed by: Bill Cunningham

C is a difficult language for a beginner. Do this book [ ... ]



Managing the Unmanageable

Author: Mickey W. Mantle & Ron Lichty
Publisher: Addison-Wesley, 2010
Pages: 464
ISBN: 978-0321822031
Audience: Software managers
Rating: 4
Reviewer: Sue Gee

This book is subtitled "Rules, Tools, and Insights for Managing Software People and Teams". Who should read it and what will they take away?

 [ ... ]


More Reviews

Last Updated ( Friday, 29 August 2014 )
 
 

   
RSS feed of book reviews only
I Programmer Book Reviews
RSS feed of all content
I Programmer Book Reviews
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.