1 / 63

Chapter 35 – Python

Chapter 35 – Python. Outline 35.1 Introduction 35.1.1 First Python Program 35.1.2 Python 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

Download Presentation

Chapter 35 – Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 35 – Python Outline 35.1 Introduction 35.1.1 First Python Program 35.1.2 Python 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.1 Setup 35.9.2 Simple DB-API Program 35.10 Operator Precedence Chart 35.11 Web Resources

  2. 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. 35.1  Introduction • Python • Interpreted • Cross-platform • Object-oriented • Large-scale Internet search engines • Small administration scripts • GUI applications • CGI scripts • Freely distributed

  4. 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. fig35_01.py(1 of 1)

  6. 35.1.1 First Python Program Fig. 35.2 Python in interactive mode.

  7. 35.1.2 Python Keywords • Python is case-sensitive • Keywords can be obtained from keyword module

  8. 35.1.2 Python Keywords Fig. 35.4 Printing Python keywords in interactive mode.

  9. 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. fig35_05.py(1 of 2)

  11. fig35_05.py(2 of 2)

  12. 35.2  Basic Data Types, Control Statements and Functions

  13. 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. fig35_07.py(1 of 3)

  15. fig35_07.py(2 of 3)

  16. fig35_07.py(3 of 3)

  17. 35.3  Tuples, Lists and Dictionaries

  18. 35.3  Tuples, Lists and Dictionaries

  19. 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

  20. fig35_10.py(1 of 2)

  21. fig35_10.py(2 of 2)

  22. 35.4  String Processing and Regular Expressions

  23. fig35_12.py(1 of 2)

  24. fig35_12.py(2 of 2)

  25. 35.4  String Processing and Regular Expressions

  26. 35.5  Exception Handling • Enables programs and programmers to identify an error when it occurs and take appropriate action • try…except blocks

  27. 35.5  Exception Handling Fig. 35.14 Interactive session illustrating a ZeroDivisionError exception.

  28. fig35_15.py(1 of 1)

  29. 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

  30. fig35_16.py(1 of 2)

  31. fig35_16.py(2 of 2)

  32. 35.7  Form Processing and Business Logic • XHTML forms • Allow users to enter data to be sent to a Web server for processing

  33. fig35_17.html(1 of 3)

  34. fig35_17.html(2 of 3)

  35. fig35_17.html(3 of 3)

  36. fig35_18.py(1 of 4)

  37. fig35_18.py(2 of 4)

  38. fig35_18.py(3 of 4)

  39. fig35_18.py(4 of 4)

  40. 35.8  Cookies • Small text files • State information • Username • Password • Specific information helpful when user returns • Etc.

  41. fig35_19.html(1 of 2)

  42. fig35_19.html(2 of 2)

  43. fig35_20.py(1 of 3)

  44. fig35_20.py(2 of 3)

  45. fig35_20.py(3 of 3)

  46. fig35_21.py(1 of 2)

  47. fig35_21.py(2 of 2)

More Related