Monday, July 28, 2014

Getting started with Python

I have been a software engineer for most of my career.  I am a bit of a nerd and programming has been both a lot of fun and a good way to provide for my family.  I was using Java for much of the last fifteen years.  Just recently I joined a small start up and was encouraged to develop some tools in Python.  After four months in Python I've decided it is a pretty good language, especially for small projects.

As such I'm putting together some resources to help my two younger daughters learn some of the basics about programming and a little about Python.  I'll share some of the resources here.  If there is a lot of interest I might do a few more posts, or expand this post.


Installing Python

To get started you'll need to install Python.  To do so go to the Download page of the Python.org site.  Python underwent a fairly major change in going from the 2.x version of the language to the 3.x version.  I suggest that you go with the newer version.  Over time the old version will fade away.

In windows, after you download the file, click on it.  It will ask if you want to run, say yes.  To complete the installation process check out Using Python on Windows.


Getting started

Once you have installed Python, click on the "Start" button and then "IDLE (Python GUI)".   This should bring up a command window with Python running.  Then type:

print ("Hello world.")

Congratulations, you have just run a simple Python program.

One of the nice things about Python is that it is interpreted, which means it will execute commands in sequence, rather than compiling the whole program before running.  This feature makes it easy to get started, but you can get bit by a bug in your program that a compiler would have flagged as a problem.


The next level is to create a file to be a Python program.  Create a file with this:

#! python
import sys
sys.stdout.write("hello from Python %s\n" % (sys.version,))

Then run it by doing:

py

Here are some more things you can try out.


Editors

To get started all you really need is a simple editor.  Something like Notepad will work just fine.  But if you want to use something designed to write programs you have lots of options. There are over a hundred editors.  I've been using Komodo at work, which has a free version that is very functional.


Learning Python

Google makes heavy use of Python.  They have some Python classes.  Here is Day 1 Part 1 and Day 1 Part 2.

Codecademy has a Python course.  I haven't used it, yet, but a friend at work found it helpful.

Python Essential Reference by David M Beasley is a fairly dense book.  A beginner will have to go slow.  But I've found it helpful and useful.


Google is your friend

One last thought: often you may get stuck.  You can often find the answer by going to Google and typing in "python" along with some of what you are trying to do.  The chances are someone else had a similar problem and the answer is already out there.


No comments: