{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture 36 week11 Python

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 2 Announcements Course Evaluation Assignment #5 - Wednesday
Background image of page 2
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 3 Part 1 10 Things About PYTHON
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
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)!
Background image of page 5

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

View Full Document Right Arrow Icon
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’)]
Background image of page 6
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’)
Background image of page 7

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

View Full Document Right Arrow Icon
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”]
Background image of page 8
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!
Background image of page 9

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

View Full Document Right Arrow Icon
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()
Background image of page 10
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
Background image of page 11

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

View Full Document Right Arrow Icon
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] The Tuple Like a constant list, (val1,...,valn) Note : The actual types of values are stored and managed internally by PYTHON (like the int, float and string).
Background image of page 12
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Software Systems 13 6: Declaring Variables There is nothing to do… syntax : VARNAME = VALUE
Background image of page 13

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

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}