Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Sunday, 24 June 2012
( Python )

From the very good video on youtube: python google

http://code.google.com/edu/languages/google-python-class/

alt P in IDLE is previous command

How to Run a Python Script

#!/usr/bin/python2.4 -tt
# Copyright 2008 Google Inc.

# Define a main() function that prints a little greeting
def main():
  print "Hello"
 
# This is the standard boilderplate that calls the main() function
if __name__ == '__main__':
  main()
 image

2 ways of running the python program

Import a Module

# sys is a module which lets you access lots of command line stuff, system stuff
import sys

# Define a main() function that prints a little greeting
def main():
  print sys.argv

image

Prints out a python list which has square brackets around it.

image

when we forget to do the import.

import takes the symbol sys, and binds it to something.

Conditionals

import sys

def Hello(name):
  if name == 'Alice' or name == 'Nick':
    print 'Alert: Alice Mode'
    name = name + '???'
  else:
    DoesNotExist(name)
  name = name + '!!!!'
  print 'Hello', name

# Define a main() function that prints a little greeting
def main():
  Hello(sys.argv[1])

image

Python does everything at the last possible second, so no compile time checking.. just runs the code.  So if it doesn’t actually see the error line, it wont catch anything.

what this means is that unit testing is important for industrial strength code.

Strings

strings are immutable

a.lower()  - this brings back a new string lowered.  a is unchanged.

a string method.

a.find(‘e’) – searches in the string for the first e.  returns index of first e.

a[0] – prints left most character

a+b – concats

‘Hi %s I have %d donuts’ %(‘Alice’, 42)

Unicode got better in Python3.

a[1:3] – up to but not including.  A slice in python.  A very pythonic feature – short and crisp!

can also use negative numbers which start at the right of the string

a[:-3] – not the last 3 characters of the string.

| | # 
# Saturday, 23 June 2012
( Python )

Created in 1990 by Guido van Rossum who now works at Google.

Supports OO and structured programming.

“A quick and light language”

Doesn’t have a really heavy type system.  Similar to Ruby, Perl, bash

python.org to download windows installer

good easy video tutorial: http://www.youtube.com/watch?v=4Mf0h3HphEA

image

should have been print (“Hello World”)

http://www.tutorialspoint.com/python/python_tutorial.pdf

google python http://www.youtube.com/watch?v=tKTZoB2Vjuk

http://thepythongamebook.com/en:start – python game book

http://inventwithpython.com/ – invent games in python… looks good!

Hello World

print (“hello world”)  - as I’m using python 3.x

image

and back to 2.7

image

Example Games in Pygame

image

first successful game running in Python.

image

another game from pygame which includes multiplater and a server.

image

http://inventwithpython.com/pygame/chapter2.html – looks like a good games tutorial

image

http://www.pygame.org/project-Colorful+Snake-2166-.html

| | #