lecture 36 week11 Python

lecture 36 week11 Python - Unix C + GNU HTML Perl Python...

Info iconThis preview shows pages 1–13. 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

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: Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 1 Introduction to Python Comp-206 : Introduction to Software Systems Week 11 Joseph Vybihal Computer Science McGill University Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 2 Announcements • Course Evaluation • Assignment #5 - Wednesday Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 3 Part 1 10 Things About PYTHON Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 4 1: A Scripting Language • PYHTON is not compiled but interpreted. • PYTHON Command-line: $ python >>> the prompt ^d to exit • Executing PYHTON code: $ python program.py Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 5 2: PYTHON is OO … even FNs • Syntax : def NAME_OF_FN(param_comma_sep) : INDENTED_STATEMENTS begin No ; only CR/LF! No { } only indentation (the tab)! Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 6 Example : def returnString(x) : “”” comments “”” return x multi-line comment Functions are objects (from calling function) : >>> print returnString(‘bob’) bob >>> print returnString._ _ doc _ _ comments >>> print returnString._ _ name _ _ returnString >>> print returnString.params.items( ) [(‘x’,’bob’)] Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 7 3: Importing code, libraries and defaults • Syntax : >>> import PYTHONFILE >>> from PYTHONFILE import OBJECT • Examples : – from BLA.PY import returnString >>> print returnString(‘bob’) – import sys >>> print sys.path >>> sys.path.append(‘/my/new/path’) Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 8 Other importing : import OS x = OS.listdir(“PATH”) if OS.path.isfile(“FILENAME”) if OS.path.isdir(“DIRNAME”) CGI Importing : import cgi form = cgi.FieldStorage() “”” get data from form as dictionary “”” if form.has_key(‘x’) : thevalue = form[“x”] Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 9 4: No main program! • Example : def fact(n) : print ‘n=‘,n if n > 1 : return n * fact(n-1) else : print ‘Done’ return 1 fact(10) Actually, think BASH! Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 10 4: Or.... • Example : def fact(n) : print ‘n=‘,n if n > 1 : return n * fact(n-1) else : print ‘Done’ return 1 def main(): fact(10) main() Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 11 4: Or ... • Example : def fact(n) : print ‘n=‘,n if n > 1 : return n * fact(n-1) else : print ‘Done’ return 1 if _ _ name _ _ == “_ _ main _ _ “ : fact(10) optional Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 12 5: Types • The Dictionary – Like HASH in PERL, {idx1:val1,...,idxn,valn} • The List – Like ARRAY in PERL, [val1,...,valn]Like ARRAY in PERL, [val1,....
View Full Document

This document was uploaded on 01/30/2011.

Page1 / 74

lecture 36 week11 Python - Unix C + GNU HTML Perl Python...

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

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