Leaning Python


The second part in the Getting Started with Python series, this article talks about strategies for learning Python, either as a first language or with previous experience, and talks about choosing and learning modules.

As with the other articles in the series, Getting Up and Running and Using an IDE, it is targeted at beginners who want to learn a general purpose programming for personal use and/or to supplement their professional skillsets.

Article Navigation

   Foundational Materials
   Getting Help
   Choosing Modules to learn
   Categorical Recommendations
     Data Processing
     Numerics
     Automation
     GUIs(non-gaming)
     Games

Basics   back to top


If you are brand new to programming, CodeAcademy - Python is a great place to start. The tutorial is done inside an interactive web browser so there's no installation to worry about.

If you have some previous experience programming, the Google Python Class is an excellent crash course with both video lectures and web page walkthroughs. After completeing the course, the set of example probelms will serve as foundations for many of you first programs.


Getting Help   back to top


Just google it!

If you type a question form query into Google the top result will most likely be a post on stackoverflow. The majority of my python knowledge comes from posts on stackoverflow. Stackoverflow is a great form where the most popular answer is voted up to the top, most any semi-common question is likely to have a answer including a good example and in-depth explanation. Most of my code is evolved form something originally copy/pasted from stackoverflow.

A lot of times when starting a new module, you want the simplest possible example of a fully working program performing one of the modules key functions. If you Google 'basic [module name] example program' you will mostly likely find a blog article giving a details walkthrough of just such and example. Copy that down down, run it, make a minor change, run it, add an more functionality, run it, etc.

My secondary source of info is the documentation for whichever module I am using, so the Python docs for any core function/module or the 3rd party docs for others. I find that these documents can be difficult to use when first working with a module, I rely almost entirely on examples from stackoverflow or other sites for module familiarization, then I start using the official documentation for more advanced application after I am already somewhat familiar with the module.


Choose which Module(s) to learn first   back to top


The power of python lies in its modules. Whatever you're interested in doing, someone has likely done almost all of the work for you an wrapped it up in an easy to use modules. In the section below, I've outlines several types of programming tasks and the modules I have experience with for those tasks. This python.org wiki page lists ~100 of the most commonly used python modules, categorically sorted.

Guidelines for picking among the modules

Generally, the more popular the module is, the more mature it is going to be, the easier it is going to be to find examples, and therefore easier to learn. I often use google trends to help chooses between similar modules. E.g. here is a google trends comparison of several popular GUI modules You an see that wxpython has traditionally been strong but has declined quite a bit, and Tkinter look to be in the lead by a fair but. Personally I use pyQt because that is used by the software I support.

A similar form of research can be done by searching the terms on stackoverflow which will be your primary source for the many small examples you'll use to teach yourself the modules. pyQt comes in at 10k hits and Tkinter comes in at 13k, both song presences.


Categorical Recommendations   back to top


The recommendations below are sorted by 'type of task' and going to follow this rough format:
Example tasks in ascending order from basic to complex

     Data Processing
     Numerics
     Automation
     GUIs(non-gaming)
     Games


Data Processing   back to top


Re

Re is Python's regular expressions module, a.k.a. regex, module. Regular expression are use for advanced string pattern matching. In addition to being useful as a did match/did not match test, grouping can be used to extract specific portions of the string/pattern for storage, manipulation, and/or (differently) formatted output.

Markup Language Parsers

There are several standardized markup languages for storing data in text files, XML and JSON are two of the most popular. In the field of engineering software, XML is totally dominate (compared to JSON) and has started to replace the more traditional arbitrary/proprietary/task specific ASCII formats used to store data.

The great thing about standardized markup languages, is they can be read and wrote using 'parsers' available in a variety of languages and you can explore/extract/manipulate their contents without having to do any text or syntax parsing yourself.

lxml (and elementTree)

lxml is a XML parser that can read an XML file into a 'tree' object (or the reverse) with a single line of code. The tree object has methods for easily accessing and manipulating the data inside. The structure of the Tree object and methods are so conducive to working with hierarchical data, that I use it in data processing applications, I use it as intermediate data structure for applications that don't even interact with XML files

Check it out at the lxml etree tutorial

In case you want a standard python alternative, elementTree a less featured (almost a subset) of lxml that is included as a standard Python. If you have working elementtree code, and you later want to change to lxml etree should just be a copy/paste affair. The opposite won't be true if you take advantage of some of the nice addition features of lxml.

A good place to start is the python elementtree tutorial


Numerics    back to top


numpy, sciPy, matlibplot Top level Site for All Three


numPy is a module for working with numerical n-dimensional arrays and provides some linear algebra functionality

sciPy extends the functionality of numpy with higher level operations such as integration and optimization

matlibplot offers a plethora of 2d and 3d plotting capabilities

These 3 libraries are the defacto standard Python numerical tools and recreate a MATLAB-esque level of numerical functionality in Python. Those who are fans of the console might also want to check out Ipytohn from sciPy's site linked above


Automation   back to top


Subprocess

Subprocess, part of the Python standard library, is for spawning, monitoring and interacting with system processes.


GUIs   back to top


PyQt

PyQt is a python binding for the Qt library, one of the most common and popular cross-platform libraries available. GUI are laid out in a graphical editor then converted to python files.

The work remaining involves connecting "signals" emitted by various graphical to "slots" which are functions. Each GUI object will have methods for changing and retrieving their contents.

Tkinter

Tkinter is a python binding for the Tk library. Its is the most popular python GUI library, marginally more popular than PyQt (though nowhere near as popular as Qt), and is part of core python.

Get started at Effbot.org Tkinter Introduction


Games   back to top


pyGame

The module that got me started in python! In pyGame you work with "rect" objects and program their 2d coordinated with respect to the time loop. pyGame has a strong community and 1000s of example games/applications on the site