Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction 35.1.1First Python Program 35.1.2Python Keywords 35.2 Basic.

Similar presentations


Presentation on theme: " 2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction 35.1.1First Python Program 35.1.2Python Keywords 35.2 Basic."— Presentation transcript:

1  2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction 35.1.1First Python Program 35.1.2Python Keywords 35.2 Basic Data Types, Control Statements and Functions 35.3 Tuples, Lists and Dictionaries 35.4 String Processing and Regular Expressions 35.5 Exception Handling 35.6 Introduction to CGI Programming 35.7 Form Processing and Business Logic 35.8 Cookies 35.9 Database Application Programming Interface (DB-API) 35.9.1Setup 35.9.2Simple DB-API Program 35.10 Operator Precedence Chart 35.11 Web Resources

2  2004 Prentice Hall, Inc. All rights reserved. Objectives In this lesson, you will learn: –To understand basic Python data types. –To understand string processing and regular expressions in Python. –To use exception handling. –To perform basic CGI tasks in Python. –To construct programs that interact with MySQL databases using the Python Database Application Programming Interface (DB-API).

3  2004 Prentice Hall, Inc. All rights reserved. 35.1 Introduction Python –Interpreted –Cross-platform –Object-oriented –Large-scale Internet search engines –Small administration scripts –GUI applications –CGI scripts –Freely distributed

4  2004 Prentice Hall, Inc. All rights reserved. 35.1.1 First Python Program Python –Can be executed on a program stored in a file –Can run in interactive mode Users enter lines of code one at a time Enables programmers to test small blocks of code quickly

5  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_01.py (1 of 1)

6  2004 Prentice Hall, Inc. All rights reserved. 35.1.1 First Python Program Fig. 35.2Python in interactive mode.

7  2004 Prentice Hall, Inc. All rights reserved. 35.1.2 Python Keywords Python is case-sensitive Keywords can be obtained from keyword module

8  2004 Prentice Hall, Inc. All rights reserved. 35.1.2 Python Keywords Fig. 35.4Printing Python keywords in interactive mode.

9  2004 Prentice Hall, Inc. All rights reserved. 35.2 Basic Data Types, Control Statements and Functions Introduces basic data types, control statements, and functions –while loop –if statement –Modulo operator ( % ) –return keyword –if … elif … else statement –Line-continuation character ( \ ) –Escape sequences

10  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_05.py (1 of 2)

11  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_05.py (2 of 2)

12  2004 Prentice Hall, Inc. All rights reserved. 35.2 Basic Data Types, Control Statements and Functions

13  2004 Prentice Hall, Inc. All rights reserved. 35.3 Tuples, Lists and Dictionaries list –A sequence of related data Tuple –A list whose elements may not be modified –Immutable –Singleton One-element tuple Dictionary –A list of values that are accessed through their associated keys

14  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_07.py (1 of 3)

15  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_07.py (2 of 3)

16  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_07.py (3 of 3)

17  2004 Prentice Hall, Inc. All rights reserved.

18 35.3 Tuples, Lists and Dictionaries

19  2004 Prentice Hall, Inc. All rights reserved. 35.3 Tuples, Lists and Dictionaries

20  2004 Prentice Hall, Inc. All rights reserved. 35.4 String Processing and Regular Expressions Regular expression –Used to search through strings, text files, databases, and so on Regular-expression string –Defines a pattern with which text data can be compared

21  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_10.py (1 of 2)

22  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_10.py (2 of 2)

23  2004 Prentice Hall, Inc. All rights reserved. 35.4 String Processing and Regular Expressions

24  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_12.py (1 of 2)

25  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_12.py (2 of 2)

26  2004 Prentice Hall, Inc. All rights reserved. 35.4 String Processing and Regular Expressions

27  2004 Prentice Hall, Inc. All rights reserved. 35.5 Exception Handling Enables programs and programmers to identify an error when it occurs and take appropriate action try … except blocks

28  2004 Prentice Hall, Inc. All rights reserved. 35.5 Exception Handling Fig. 35.14Interactive session illustrating a ZeroDivisionError exception.

29  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_15.py (1 of 1)

30  2004 Prentice Hall, Inc. All rights reserved. 35.6 Introduction to CGI Programming Use Python on the Web –cgi For access to XHTML forms Directive (pound-bang or Shebang) –Provides server with location of Python executable cgi module –Provides functionalities for writing CGI scripts environ data member –Holds all environment variables –Cookie To read and write cookies –smtplib To manipulate SMTP messages –urllib To manipulate Web data –ftplib To perform client-side FTP tasks

31  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_16.py (1 of 2)

32  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_16.py (2 of 2)

33  2004 Prentice Hall, Inc. All rights reserved. 35.7 Form Processing and Business Logic XHTML forms –Allow users to enter data to be sent to a Web server for processing

34  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_17.html (1 of 3)

35  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_17.html (2 of 3)

36  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_17.html (3 of 3)

37  2004 Prentice Hall, Inc. All rights reserved.

38 Outline fig35_18.py (1 of 4)

39  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_18.py (2 of 4)

40  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_18.py (3 of 4)

41  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_18.py (4 of 4)

42  2004 Prentice Hall, Inc. All rights reserved. 35.8 Cookies Small text files –State information Username Password Specific information helpful when user returns Etc.

43  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_19.html (1 of 2)

44  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_19.html (2 of 2)

45  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_20.py (1 of 3)

46  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_20.py (2 of 3)

47  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_20.py (3 of 3)

48  2004 Prentice Hall, Inc. All rights reserved.

49 Outline fig35_21.py (1 of 2)

50  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_21.py (2 of 2)

51  2004 Prentice Hall, Inc. All rights reserved. 35.9 Database Application Programming Interface (DB-API) Python Database Special Interest Group (SIG) –Formed to develop a specification for Python database application programming interface (DB-API)

52  2004 Prentice Hall, Inc. All rights reserved. 35.9.1 Setup MySQL and the MySQLdb module must be installed

53  2004 Prentice Hall, Inc. All rights reserved. 35.9.2 Simple DB-API Program Lets user choose an author from XHTML drop- down list User clicks button to query database Database query returns a list of all books by author

54  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_22.py (1 of 2)

55  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_22.py (2 of 2)

56  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_23.py 1 of 3

57  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_23.py (2 of 3)

58  2004 Prentice Hall, Inc. All rights reserved. Outline fig35_23.py (3 of 3)

59  2004 Prentice Hall, Inc. All rights reserved.

60 35.10 Operator Precedence Chart

61  2004 Prentice Hall, Inc. All rights reserved. 35.10 Operator Precedence Chart

62  2004 Prentice Hall, Inc. All rights reserved. 35.10 Operator Precedence Chart

63  2004 Prentice Hall, Inc. All rights reserved. 35.11 Web Resources www.python.org www.zope.com www.zope.org starship.python.net www.python.org/download/download_mac.html www.vex.net/parnassus www.pythonware.com starship.python.net/crew/davem/cgifaq/faqw.cgi www.devshed.com/Server_Side/Python/CGI starship.python.net/crew/aaron_watters/pws.html www.python.org/doc/howto/regex/regex.html www.python.org/windows/win32com gadfly.sourceforge.net aspn.activestate.com/ASPN/Python/Cookbook www.python.org/windows/win32/odbc.html starship.python.net/crew/bwilk/access.html www.python.org/doc/Comparisons.html www.vic.auug.org.au/auugvic/av_paper_python.html www.networkcomputing.com/unixworld/tutorial/005/005.html


Download ppt " 2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction 35.1.1First Python Program 35.1.2Python Keywords 35.2 Basic."

Similar presentations


Ads by Google