lect3-python.ppt - Andrew McCallum, UMass Amherst,...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Introduction to Python Lecture #3 Computational Linguistics CMPSCI 591N, Spring 2006 University of Massachusetts Amherst Andrew McCallum Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Today’s Main Points • Check in on HW#1. • Intro to Python computer programming language. • Some examples Linguistic applications. • The NLTK toolkit. • Pointers to more Python resources. Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Python Outline • Introduction – Python attributes and ‘Why Python?’ – Running programs – Modules • Basic object types – Numbers and variables – Strings – Lists, Tuples – Dictionaries • Control Flow – Conditionals – Loops Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Python Features • Free. Runs on many different machines. • Easy to read. – Perl = “write only language” • Quick to throw something together. – NaiveBayes Java vs Python • Powerful. Object-oriented. • THE modern choice for CompLing. • NLTK Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Using Python Interactively $ python >>> print “Hello everyone!” Hello everyone! >>> print 2+2 4 >>> myname = “Andrew” >>> myname ‘Andrew’ The easiest way to give Python a whirl is interactively. ( Human typing in red. Machine responses in black.) Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Modules print 25*3 # multiply by 3 print ‘CompLing ‘ + ‘lecture 3’ # concatenate with + myname = ‘Andrew’ To save code you need to write it in fles. Module : a text fle containing Python code. Example: write the Following to fle foo.py $ python foo.py 75 CompLing lecture 3 $ (No leading spaces!) Then run it as Follows: Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Importing Modules $ python >>> import foo 75 CompLing lecture 3 >>> foo.myname ‘Andrew’ Every fle ending in .py is a Python module. Modules can contain attributes such as Functions. We can import this module into Python. Andrew McCallum, UMass Amherst, including material from Eqan Klein and Steve Renals, at Univ Edinburghh Module Reloading >>> import foo 75 CompLing lecture 3 Importing is expensive--after the Frst import of a module, repeated imports have no effect (even if you have edited it). Use reload to force Python to rerun the Fle again....
View Full Document

This note was uploaded on 02/22/2012 for the course CMPSCI 585 taught by Professor Staff during the Fall '08 term at UMass (Amherst).

Page1 / 50

lect3-python.ppt - Andrew McCallum, UMass Amherst,...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online