Choose Your Own Pyventure/old toc page

Purpose
This book is the curriculum book for the Twin Cities ExCo (Experimental College) class Bits and Bites: Programming First Steps

Do you think that programmers are born with keyboards in their hands? Programmers are made, not born—you too can code with the best of them. If you're interested in breaking down the barriers and mystique around programming, join us! Learn to code in a chill, non-judgmental environment.

Your facilitators, Gregg and Amanda, come from non-traditional programming backgrounds, and used to be N00bs. We have no patience for alpha geeks, macho baloney, and geek superiority.

Our big project is a web application that allows you to play a "Choose Your Own Adventure" that you write yourself! (example: http://cyoa.lind-beil.net/).

All instruction is done in the Python language, a free, open-source, cross-platform, powerful yet easy to learn language. We'll help get you going, introducing new concepts weekly. There will be hands-on assignments, lots of time for questions, and a loosely structured feel. Hacking is about liberation and democratizing power.

Prerequisites: Access to a computer where you can run or install programs. Online only is fine, but learning is better in meat space (where you'll need access to a laptop, or really strong arms to haul your desktop).

Programmers with experience are also welcome as learners or mentors.

Please let us know about any requirements around mobility, neurodiversity, or child-care needs, and we will do our best to meet them.

Why Another Python Book?
We were inspired by:

Kirrily Roberts' OSCON Presentation and Dreamwidth's Python vs. Ruby Deathmatch.

Windows
'''1a. Python, from the Python website'''

You will want the newest 2.x series (probably 2.6.x) release, NOT a 3.x.x release. Python 3 has some differences (primarily around strings) that this class doesn't address. If you're more adventurous, feel free to try one of the installations towards the bottom of the page:
 * ActiveState ActivePython (not open source)
 * Enthought Python Distribution (a commercial distribution for scientific computing)
 * Portable Python (Python and add-on packages configured to run off a portable dice) (Recommended if you can't install python system-wide, and need to run it off a USB stick, SD card, or the like)

Those distributions have additional modules (bundles of code) we're not going to use. If you get serious with Python, installing one of these bundles can be much easier than installing pieces piecemeal. Install it using the usual windows methods.

'''1b. Test your Python installation.'''

start > run > cmd [OK] This will open a Windows cmd window. In it, type python: C:\Documents and Settings\Gregg>python Python 2.4.3 - [some other info, perhaps] >>> 'hello' 'hello'

If you see something like this, then you're good!

'''2a. Install A Text Editor.'''

Word processors, including Microsoft Word and friends, are terrible for writing code, since they conflate layout formatting and text.Simpler is better. That said, Notepad is terrible also, because it automagically appends on '.txt' onto filenames, and other niceties.

Key features of a good programming editor:
 * syntax highlighting
 * fixed-width font
 * multiple tabbed interface.

A good, free (as in beer, and open-source) one that we like a lot is SciTE. This program also has a "no install" version found at from SourceForge The portable versions doesn't quite have all the features of the installed version, but is quite capable. A good sign in programs is when they can exist in a form that doesn't require an installer. This implies the developers don't want to interfere with a running system, or damage anything, and make it easy to get rid of the program if you don't like it.

'''2b. Test your installation'''

Double click on SciTE, or choose it from the Programs menu, or click on the executable, in the usual Windows ways. You should get a Notepad looking workspace.

Copy in paste this in:

# here is some python code 1 # an int b = 'some string' # string if 2 > 1: print "sure looks bigger"

Then, in the menu: Language > Python. The code should change change colors, and the various parts (variables, integers, strings, comments) will be nice colors.

Mac OS X
Good news Mac users! Python comes preinstalled as part of the Mac OS. Check it out:

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type "help", "copyright", "credits" or "license" for more information. ( >>> print "hello"  'hello'
 * 1) In Finder, navigate to Applications -> Utilities -> Terminal and start up the Terminal
 * 2) Type python and hit enter
 * 3) You will see something like this:

You can do a lot in the Python command prompt but writing more complex problems will be easier with a text editor. TextWrangler is a good text editor for Mac users. Download it from the Barebones Software Site

Both
(Optional) Install 

Ipython is a python package that gives a much nicer command-line environment, which includes syntax highlighting, history, and a variety of debugging tools and improvements. Download it from the Ipython site.

Related Tools
PyScripter is a free IDE (available for Windows. If you have previous programming experience - this is similar to the Borland Delphi IDE. You can download PyScripter from PyScipter project site.

Lesson 0
After running this, you should see:

"Hello, world!"

Play Around With 

The Python  module, is a simple reimplementation of a LOGO-like language.

From your python prompt:

All the commands are listed at the Turtle reference documentation

Lesson 1
no line numbers, but can be copy and pasted