Choose Your Own Pyventure

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! If (sadpants), you see something like

'python' is not recognized as an   internal or external command, operable program or batch file.

then python (the 'interpreter' program that can translate Python into "computer instructions") isn't on your path (see Putting Python in Your Path below). Then try calling it like this (assuming Python2.6, installed in the usual location, ):

\> C:\Python26\python.exe

'''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 and 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.

Putting Python In Your Path
In order to run programs, your operating system looks in various places, and tries to match the name of the program / command you typed with some programs along the way. This list of folders and locations is called the (System) Path. Confusingly, path also refers to the path to a particular file or directory on a system, described as a 'full path' or 'relative path', depending on context. This article is about how to put the Python interpreter on the System Path to make our command line know what to do when the user types.

Windows
First see if the directory is on the path or not. From a windows  prompt:

> path

This will output the system path. See if  (or equivalent) is on it. If not, you need to add it.

control panel > system > advanced > |Environmental Variables| > system variables -> Path

This needs to include:   (or equivalent). If you put it at the front, it will be the first place looked. You can also add it at the end, which is possibly saner.

Then restart your prompt, and try typing 'python'. If it all worked, you should get the soon-to-be-familiar  prompt.

Python IDEs
In this course / book, we won't use any IDE's (Integrated Development Environments), because this is a course about programming, not learning an IDE. For the advanced programmer, they can speed up work by helping organize code, autocompleting variable names, and other things. Gregg doesn't use or endorse any of these, and tends to use Scite and Git for his dev work.

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.

There are other IDEs with Python code support as well (Komodo, Eclipse).

Interactive
First taste

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

Batch / From A File
Save this in your favorite text editor, as 'lesson0.py'

Then open a prompt, navigate (see below) to where you saved the file and run:

prompt> python lesson0.py

Navigation
changes directories. goes up a directory

lists contents of a directory. By default, it lists the current directory. 'ls' is bash/mac; 'dir' is windows'.

print working directory. Where the heck am I? (This is spelled 'cd' (no arguments) in Windows).

Lesson 1: Welcome to Mysterious Mansion
no line numbers, but can be copy and pasted

Goals

 * 1) Nested conditional statements
 * 2) Introduce new python data type, the dict
 * 3) Introduction to functions

Nested Conditional Statements
How would we expand our code to encompass more rooms and paths? We can use nested conditional statements:

Exercises:


 * 1) What are benefits and drawbacks to this approach?
 * 2) Suppose that you wanted to give the user a second chance.  If they choose to 'stay', then 'yes', send them through the door.  How would you implement this?
 * 3) How would this approach scale to hundreds of rooms?
 * 4) Moving towards maps
 * 5) rewrite the code, numbering the rooms / state
 * 6) make a map (flowchart) of all the possible paths through the game

Python Dictionaries
0-level: is like a paper dictionary, in that there are entries and definitions. Like in a paper dictionary, this gives particular definitions names for ease of finding. It is much easier to go look up the definition for "octothorp" than have to remember that the definition for "octothorp" is on page 861. In Python, we call the entries keys and the definitions values. s are used for lots of tasks in python, including indexing, graphs, and data storage.

1-level: in Python there are many ways to construct a dictionary. Here is one:

symbol_names = { '#': 'octothorp', '!': 'exclamation point', '?': 'question mark', ' ': 'space', ',': 'comma', '.': 'full stop', ':': 'colon' }

We could use this to print out the letters punction in a sentence like this:

for letter in "Here is my sentence. It has grawlix:  #!?!": # there is shorthand for the next for line: dict.get(thing, default) # print symbol_names.get(letter,letter) if letter in symbol_names: print symbol_names[letter] # [] 'indexes' the dict # some_dict[key] -> get value for key in some_dict # by analogue, some_dict[key] = value sets it. else: print letter

2-level: Python dictionaries (dicts) aren't 'really' like paper dictionaries.

a. dict's have no inherent order, and especially don't have alphabetical order. In memory, the thing after 'octothorp' might be '2'. Think of them more as someone's kitchen. There well labeled drawers all over. When you ask for something (like a mixing spoon), the kitchen owner says, "those are in Drawer 13, let me get one". It doesn't matter what else is in Drawer 13.

b. The keys don't have to be strings, and values can be almost anything, including strings, lists, objects, functions and other dicts. The keys do have to be immuatable though.

3-level: In other languages dicts are called (variously) hashes, associative arrays, or maps (mappings). Map(ping) emphasizes the 'correspondence' aspect. Associative array is obvious (associate an identifier with a position in an array), but why 'hash'? Well, as it turns out, it's not just a love for breakfast meat, or Amsterdam. Among other things, a 'hash' is a function that takes data and returns a string, in a systematic way. As an example, the hash function  is like the hash that paperdictionaries use. The problem with it is that then some sections of thedictionary are big (like s and t) while some (e.g., q, x, z) are very small.

In computing terms, it's much better if the hash is uniform, meaning that the output is spread evenly over the answer space. Thinking back to our kitchen example earlier, uniform hashing is important so that no particular drawer gets too full. Dicts have fast lookup because they make lots of shallow drawers. If it's fast to figure out which drawer you need to look in, and if there's not much in each drawer, then finding particular items is easy. In terms of Computational Complexity, lookup and entry are O(1).

Exercises:

'Put it all together'

Turn the game flowmap into a dictionary of lists, like this:

gamemap = {1: [2,3], 2: [4,5]}

Homework
a. make it: make a dict of the digit names, then a function that prints the name of each digit in an inputted string.

b. make it robust: make it so that it can handle inputted ints, and strip out all non-digits, so that output like 1111 and '2 and 1 is 3' will be handled well

Goals

 * 1) Functions
 * 2) * signatures
 * 3) * arguments
 * 4) *# named and positional
 * 5) *# default
 * 6) * Printing is not Returning
 * 7) * docstrings
 * 8) Recursive Functions
 * 9) * (See immediate previous)
 * 10) Imports
 * 11) Randomness (PRNGs)
 * 12) Data Types
 * 13) *  Boolean (True/False)
 * 14) *  Lists
 * 15) *  None

Anatomy of a Function
Functions and data structures are the twin bases of programming. At its core programming is about taking state, and changing it. As such, we're going to take a little time here to talk more heavily about functions, in a level of syntactic detail that we've avoided until now.

In Python, function definitions are spelled:


 * def :: signals to python that we're defining a function
 * function_name :: a valid identifier naming the function
 * ([optional named and positional arguments])
 * the parentheses are required, but the function may or may not take arguments, which are execution-time parameters for the function, that can affect how it runs.
 * python supports named and positional arguments, as well as optional values, which we'll explore more below.
 * ':' :: the colon character
 * one or more lines of code. If you want a function to do nothing, use the   statement
 * all functions return a value. By default this is the special value

Function Signatures
A function signature simply describes the inputs and outputs of a function in a conventient shorthand, using pseudocode. As an example, look at range from the standard library:

range([start,] stop[, step]) -> list of integers

The bracketed arguments imply that these are optional arguments. Thus if one argument is given, it will go in the 'stop' slot, if two, then 'start','stop', and if three are given 'start','stop','step'.

Creating Your Own Functions
We've come across a Python function already:. This is an example of one of the many "built in" functions that are part of the Python language standard distribution (thus, always available). Other functions live in modules that need to be imported. Some modules come with Python (the standard library), or you can create your own, or use ones downloaded from the internet. Using built-in functions is very easy and creating your own is not much harder!

-- More on Modules
A module is any file containing Python definitions and statements that we can access from other python programs. To import a module, it must either be in the standard library, on the, or a file in the same directory as the running   process. Let's explore a the  module, which we'll use for our wandering Grue!

# random is in the standard library >>> import random >>> dir(random) ['BPF', 'LOG4', 'NV_MAGICCONST', 'Random', 'SG_MAGICCONST', 'TWOPI', 'WichmannHill', '_BuiltinMethodType', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_acos', '_cos', '_e', '_exp', '_floor', '_inst', '_log', '_pi', '_random', '_sin', '_sqrt', '_test', '_test_generator', 'betavariate', 'choice', 'cunifvariate', 'expovariate', 'gammavariate', 'gauss', 'getstate', 'jumpahead', 'lognormvariate', 'normalvariate', 'paretovariate', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'stdgamma', 'uniform', 'vonmisesvariate', 'weibullvariate']

You can also type, or from the command line (not the Python interpreter)

$ pydoc random $ pydoc random.shuffle # for example

to see full docstring based help files.

Notice the function random appears in that list. To call a function from a module, you need to tell Python what module you're using as we did in the above function with the Grue.

>>> import random >>> random.random 0.73015823962912774   >>> random.randint(2,800) 158 Check out the Python documentation for the module you want to use if you want to know what each function does and how to use it. Here is the documentation for the random module: http://docs.python.org/library/random.html

Wandering Grue

Exercises

 Explore  more. In some directory, copy this text to a file, called my.py

Open a python prompt in that directory. Try running this code:

Q: What is going on with ? What does  really do?

 

Recursive Functions
See Recursive Functions

You loop, until it's time not to loop. -- adpated from Patrick Swayze (RIP), Roadhouse

Recursive functions are functions that call themselves from inside their definition. Confusing! Be forewarned: recursion is kind of spicy stuff, so don't worry if it takes you awhile to wrap your brain around it. Here's an example of a recursive function:

Notice that at the end, we call the function  at point 'R' from inside the function definition. How does Python know what to do with a function if it hasn't been defined yet?!

The answer is: it doesn't.  And it doesn't need to. There are multiple stages in interpreting code. During definition (when you define a function), Python looks over the code for any syntax errors, like improper indentation, or you type 'pring' instead of 'print', but it doesn't actually execute any of the code. It sees, and assigns the token "yesorno" as a reference to a function (defined by the definition). is just like any other variable. Since it's syntactically correct, it continues through the code. It's only when you call the function (execution) that Python cares about the fact that it's a function and will execute it as thus, since it's already defined!

Before continuing, try the code. Give it some bad answers.

The point of recursion here is so that the question "Yes or No? " will keep getting asked until the user inputs either 'yes' or 'no'. This prompt is much better behaved (and robust) than our original conditional/branching logic in Lesson 1.

Here is a more complicated example of how we can use recursive function in our Choose Your Own Adventure games:

There are two things to notice here - the function accepts an argument, "choices," and when the function is called at the end of the definition it is called with the argument choices. In the Python interpreter, define your dictionary called book like this (feel free to be creative and change the pages around, etc.):

>>>book={ 'foyer' : {'desc' : "Some text", 'choices' : ['bathroom','kitchen',], }, 'bathroom' : {'desc':"Some text", 'choices' : ['change toilet paper','leave'] }, 'kitchen' : {'desc':"Some text", 'choices' : ['eat the cake', "don't eat the cake"]}, 'eat the cake':{'desc':"Some text",'choices':['have a glass of water','wash the plate']}, "don't eat the cake":{'desc':"Some text",'choices':['put the cake in the fridge','sit down']}, }

Then define the function as you've done in the examples above. Call the function like this:

>>> move(book['foyer']['choices'])

What happens should look like this:

>>> move(book['foyer']['choices']) bathroom kitchen

What next?

Type in something other than the choices listed. What happens? Type in one of the listed choices. What happens then?

Now try defining the function like this:

Call the function as before. Try giving it a choice that isn't listed. What happens? You should get an error like this:

Traceback (most recent call last): File " ", line 1, in      File " ", line 12, in move TypeError: move takes exactly 1 argument (0 given)

The problem is explained in the last line of the error. The function we defined takes exactly 1 argument, but when we called it the second time (by giving it the invalid choice) we didn't give it any arguments so it flubs.

Goals

 * 1) midclass review
 * 2) CYOA data and action model
 * 3) using the command line to call a script

Midclass Review
FIRST!!!, do the Midclass Review

Modeling A Choose Your Own Adventure Game
Computer programs are composed of DATA modeling a problem space and FUNCTIONS to operate on (manipulate, transform, and display) those data.

Data, or What is the What?
Imagine that you are holding a choose your adventure book.

 What is it? What are its parts?

 How do you know where to start?

  Does Page 1 mean anything?

  What are the parts of each page?

 

Let's use our real-world domain-space knowledge to create a practical data model. Our data model should be sophisticated enough to model the domain, without getting over-burdened in details. If we need to make it more detailed later, we can.

For each of these pieces, decide the following:


 * how many of them are there? Zero, zero-or-more (0+), (exactly) one, one or more (1+), or some other exact number?
 * how does one identify them? By unique id (U), index position, or in some other way?
 * is the item contained in / part of another structure? Does it have children or parents?

<ol> <li>Book</li> <li>Page</li> <li>Page Number</li> <li>Description</li> <li>Choice</li> </ol>

Data Diagram
Putting this all together, a model for a Choose Your Own Adventure might be:

DATA MODEL FOR A CYOA, a kind of decision tree Book CONTAINING pages CONTAINING (1+) unique id (1) description (1) words in paragraphs (0+) choices (0+ -> leaf/ending, 1+ -> node) choice text / description / information jump / pointer to another unique id

Next, we map these ideas on Python data types:

Book = dict with key:value -> pageid:Page Page = dict with key:value pageid: str desc: str choices: iterable/sequence of choices (list, dict, or set) choice contains: choicetext # str, something like "Go through the door" pageid    # pointer to another page

Here is an example data structure for our game.

For the sake of simplicity, we have ignored some bits (copyright, front and back cover, etc.). But it's easy to add them back in if one is so inclined.

Exercises:

<ul> <li>Note we have a mix of strings and ints naming our pages. What are the problems with this approach? Benefits? On the whole, is this wise, and if not, what is a better approach? </li> <li>Will allowing tokens like "the dark" as room names cause us problems? </li> </ul>

Extra credit:

<ul> <li> Recall that our 'game data' is simply a dictionary, and recall that it is trivial to add new items to a dictionary. Use this to include COPYRIGHT, INTRODUCTION, and AUTHOR INFORMATION to our game.

</li> </ul>

Actions

 * Imagine yourself holding the book. What actions does one do to interact with the story?


 * How does the book end? How does one know when to stop reading?

Putting It All Together
Let's model the game flow using pseudocode. This pseudocode will help us figure out what functions we need to create, and what they should take as arguments. There are an infinite number of ways to do any programming task, and we will indicate, and the provisional nature of our pseudocode throughout. We may even through it all out and start from scratch if we need to!

GAME FLOW display_description(roomid) # print to screen print Book[roomid]['desc'] print choices (number them?) next_room_id = user_choose( choices? ) [repeat until user QUITS or we reach an ENDING! (An ending means that the user has no place to go)

First Draft - 20 Miles of Bad Code
Check out this code here. Warning! There be some bad code behind that link. Think about the major things that are wrong with it and how it can be fixed and improved.

Second Draft - Patching the Holes
Second draft

Exercises

<ol> <li>Note that  is now  -based, rather than recursive. </li> <li>Write a 'pages' dict that will fail </li> <li>ADVANCED. Using your favorite search engine, investigate the "if '__name__' == 'main'" stuff at the end of the file.

</li> </ol>

and calling from the command line
(if name is main, import context and more) -- TODO

Goals

 * 1) Understanding the HTTP Request
 * 2) Introducing web.py

Snowpants, a Love Story
So, you think you know the web. Sure, you can surf the web, send twits, read electronic telegrams, and control a Level 50 Dermatologist in World of Wartcraft, but do you know what goes on under the hood?

Dramatis Personnae (the players)


 * Minnie, a web user in Minneapolis
 * Brow, a web browser
 * Servo, a web server program
 * Mac, a computer in Yellowknife
 * YellowSnow, a NSP (network service provider) in Yellowknife

The curtain opens. Minnie types  into her web browser. After filling out a form, she receives an email and a text message saying "Fear not! Longjohns are on the way!" and weeks later, they arrive. The crowd cheers, and legs are warm!

So, what happens backstage?

<ol> <li> When Minnie types the url into Brow, and hits enter, some magic happens and the domain name  is translated (resolved) into an IP address. The browser program creates an HTTP Request, which is just a specially formatted text message, which it tries to send. Inside this message is a lot of information... where the request comes from, the URL host and path requested, timestamps and other housekeeping information, and more. </li>

<li>More routing magic happens happens, and the request makes its way over wires and by dogsled to Yellowknife, where Mac, the computer that hosts the " sendwarmclothes.org " website, lives. </li>

<li>Mac has lots of programs that run on it. It can handle email, has a popular Boggle program that users love, and produces enough heat that the employees at YellowSnow huddle around it for warmth. The staff of "Send Warm Clothes" actually live in San Diego, where winter clothes are extermely cheap, but decided they would have more snow-cred if their website was hosted in western Canada. Along with this busy and fulfilling life, Mac runs a program called Servo, a web server program. Some web servers include Apache and IIS, but there are many others.</li>

<li>Servo's job in life is to listen on a certain set of ports (among these: 80 for HTTP and 443 for HTTPS), and respond if any messages (HTTP requests) come in on those ports.

<ul> <li>0-level: In concept, responding is quite simple. When an HTTP request comes in, the server knows the format of these special messages, decodes them, and returns a specially formatted text message (the response) in reply. </li>

<li>1-level: The magic happens by putting special things in the body of the response. As part of the response, it describes what kind of special text it's returning, such as: ,   , or. It's the job of the browser to figure what to do with this data. This may involve opening another program (like Adobe Acrobat, OpenOffice), sending it to a plugin (like Flash), or displaying the text to the screen.</li>

<li>2-level: The most common (and initial/original) way of understanding what to do with the URL request path (the   part), is to map this onto a filesystem, and return some file from. Let's suppose that Servo's has a base web directory on Mac at .   It uses this directory as the base for all file-serving requests. Then, if Servo were an Apache server, it would try to return an html response filled with the contents of .</li>

<li>3-level: Servo, however, is a liberated, free-thinking, modern web server, written in Python. He lives in the city in his own apartment, has a good day job, he's making it on his own! Servo realizes that a url is just data , and he can respond however it makes sense to. Instead of trying to find a file, he is programmed to parse the url into a series of actions: . There is no directory called snowpants anywhere on Mac. </li> </ul>

<li> Servo, the very model of a modern web server, is programmed to interpret the request URL as a series of directives , and does a series of actions. It sends a text message to Minnie's phone, an email to the warehouse in San Diego, and builds a text response to send back to Minnie's computer. The text response consists of some html text describing Servo's actions, and exhorting Minnie to valiantly struggle on until the longjohn's arrive. It sends the response back to the IP address in the original request. </li>

<li> The response comes back to Minneapolis. Brow interprets it correctly as html, and prints it to the screen, where Minnie sees it.</li>

</ol>

Example URLs

From 6pm.com, a shoe merchant:

From part of a url produced by a MapServer application:

Exercises

 * 1) What are the patterns in these urls?
 * 2) Look at the 6pm example.  What python data structure would be easy to map on the parts of this url?
 * 3) Look at the urlparse module in the standard library.  Use the   and   functions to parse these urls

-- a Simple Web Framework
Web.py is a web framework written in Python that we will use for creating a web-based front end for our CYOA application. A web framework is a set of modules and functions that automate and simplify http request parsing and http response generation. Typically these frameworks include bits that handle language and filetype encoding, generating correct error codes, parsing url requests and other fiddly bits of that ilk. The website author is responsible for styling, content, user interaction and other site-specific bits.

We are using  because it is very simple to set up, and has a low barrier to entry. Other frameworks may scale better, or have more features. For a simple web site, like the one we're making, we want to get into coding as quickly as possible.

Hello World! in Web.py
(These instructions slightly augment the ones at web.py, to ease installation for Windows users)


 * 1) Go to web.py.
 * 2) Download the tarball or zip-file of the web.py code.  If you don't know what a tarball is, then you want the zipped code.
 * 3) (zip specific)  Unzip the zipped webpy code using your favorite unzip utility.  In Windows, you might have to double click on the file, or right-click and say "open with > compressed (zipped) folders)
 * 4)  (tarball)
 * 5) Create a project directory somewhere /path/to/webcyoa
 * 6) Copy the web subdirectory of the   code to your project directory
 * 7) Create a file   containing the contents of /Webpy Hello World
 * 8) From here, you're caught up with the web.py main page, and you can look for more help at the tutorial.
 * 9) Fire up the webapp!
 * 10) python code.py
 * 11) you should see something like:   .  If so, your webserver is now running on Localhost (see below) and listening on port 8080.
 * 12) if you get an , then make sure you have the   folder in your project dir.
 * 13) Fire up your web-browser and type in http://localhost:8080
 * 14) * You should see "Hello World"
 * 15) * in your shell window, you should see something like:
 * 1) * You should see "Hello World"
 * 2) * in your shell window, you should see something like:

Localhost
Who is localhost and what is he hosting, exactly? And why is it on my computer?

localhost is simply the conventional name for you your computer. The ip address  is reserved for the local machine. (for the observant) is special address which binds to all local interfaces with ip address. Details to review at your leisure, but the idea here is that it's running locally. Requests from outside your machine probably won't work.

GET and POST
The usual kind of http request is a GET address. When you submit a form on a page, it triggers a POST request. Thus if you wanted a webpy class to respond different when a form is submitted, give it a POST method. There are other http request types including PUT and DELETE that never really caught on in the wild.

Exercises

 * 1) Research Python classes.  Use your favorite search engine.  Come with questions.
 * 2) Change the method of the   method, so that it prints "Hello, the current time is.... [now]" where [now] is the current time (cf:  )
 * 3) Explore how to serve static content, based on the tutorial.

Goals

 * 1) The concept of interfaces
 * 2) making code abstract
 * 3) from command-line to webapp

Goals

 * 1) expansion and hackability