text
stringlengths
0
3.52k
For Denise, my wife.
Preface
Some of the key aspects of this book are:
It assumes knowledge of Python 3 and of concepts such as functions, classes, protocols, Abstract Base Classes, decorators, iterables, collection types (such as List and Tuple) etc.
However, the book assumes very little knowledge or experience of the topics presented.
The book is divided into eight topic areas; Computer graphics, Games, Testing, File Input/Output, Database Access, Logging, Concurrency and Parallelism and Network Programming.
Each topic in the book has an introductory chapter followed by chapters that delve into that topic.
The book includes exercises at the end of most chapters.
All code examples (and exercise solutions) are provided on line in a GitHub repository.
Chapter Organisation
Each chapter has a brief introduction, the main body of the chapter, followed by a list of online references that can be used for further reading.
Following this there is typically an Exercises section that lists one or more exercises that build on the skills you will have learnt in that chapter.
Sample solutions to the exercises are available in a GitHub repository that supports this book.
vii
viii Preface
What You Need
You can of course just read this book; however following the examples in this book will ensure that you get as much as possible out of the content.
For this you will need a computer.
Python is a cross platform programming language and as such you can use Python on a Windows PC, a Linux Box or an Apple Mac etc. This means that you are not tied to a particular type of operating system; you can use whatever you have available.
However you will need to install some software on your computer. At a mini- mum you will need Python. The focus of this book is Python 3 so that is the version that is assumed for all examples and exercises. As Python is available for a wide range of platforms from Windows, to Mac OS and Linux; you will need to ensure that you download the version for your operating system.
Python can be downloaded from the main Python web site which can be found at http://www.python.org.
You will also need some form of editor in which to write your programs. There are numerous generic programming editors available for different operating systems with VIM on Linux, Notepad++ on Windows and Sublime Text on Windows and Macs being popular choices.
Preface ix
However, using a IDE (Integrated Development Environment) editor such as PyCharm can make writing and running your programs much easier.
However, this book doesn’t assume any particular editor, IDE or environment (other than Python 3 itself).
Python Versions
Currently there are two main versions of Python called Python 2 and Python 3.
Python 2 was launched in October 2000 and has been, and still is, very widely used.
Python 3 was launched in December 2008 and is a major revision to the lan- guage that is not backward compatible.
The issues between the two versions can be highlighted by the simple print facility:
In Python 2 this is written as print ‘Hello World’
In Python 3 this is written as print (‘Hello World’)
It may not look like much of a difference but the inclusion of the ‘()’ marks a major change and means that any code written for one version of Python will probably not run on the other version. There are tools available, such as the 2to3 utility, that will (partially) automate translation from Python 2 to Python 3 but in
general you are still left with significant work to do. This then raises the question which version to use?
Although interest in Python 3 is steadily increasing there are many organisations that are still using Python 2. Choosing which version to use is a constant concern for many companies.
However, the Python 2 end of life plan was initially announced back in 2015 and although it has been postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to Python 3, it is still living on borrowed time. Python 3 is the future of the Python language and it is this version that has introduced many of the new and improved language and library features (that have admittedly been back ported to Python 2 in many cases). This book is solely focussed on Python 3.
Useful Python Resources
There are a wide range of resources on the web for Python; we will highlight a few here that you should bookmark. We will not keep referring to these to avoid repetition but you can refer back to this section whenever you need to:
https://en.wikipedia.org/wiki/Python_Software_Foundation Python Software Foundation.
x Preface
https://docs.python.org/3/ The main Python 3 documentation site. It contains tutorials, library references, set up and installation guides as well as Python how-tos.
https://docs.python.org/3/library/index.html A list of all the builtin features for the Python language—this is where you can find online documentation for the various class and functions that we will be using throughout this book.
https://pymotw.com/3/ the Python 3 Module of the week site. This site contains many, many Python modules with short examples and explanations of what the modules do. A Python module is a library of features that build on and expand the core Python language. For example, if you are interested in building games using Python then pygame is a module specifically designed to make this easier.
https://www.fullstackpython.com/email.html is a monthly newsletter that focusses on a single Python topic each month, such as a new library or module.
http://www.pythonweekly.com/ is a free weekly summary of the latest Python articles, projects, videos and upcoming events.
Each section of the book will provide additional online references relevant to the topic being discussed.
Conventions
Throughout this book you will find a number of conventions used for text styles. These text styles distinguish between different kinds of information.
Code words, variable and Python values, used within the main body of the text, are shown using a Courier font. For example:
This program creates a top level window (the wx.Frame) and gives it a title. It also creates a label (a wx.StaticText object) to be displayed within the frame.
In the above paragraph wx.Frame and wx.StaticText are classes available in a Python graphical user interface library.