1. Trang chủ
  2. » Kinh Doanh - Tiếp Thị

Making use of python phần 1 ppsx

42 335 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 42
Dung lượng 897,71 KB

Nội dung

TEAM LinG - Live, Informative, Non-cost and Genuine! Making Use of Python TEAM LinG - Live, Informative, Non-cost and Genuine! TEAM LinG - Live, Informative, Non-cost and Genuine! Wiley Publishing, Inc. Rashi Gupta Making Use of Python TEAM LinG - Live, Informative, Non-cost and Genuine! Publisher: Robert Ipsen Editor: Ben Ryan Managing Editor: Angela Smith New Media Editor: Brian Snapp Text Design & Composition: John Wiley Composition Services Designations used by companies to distinguish their products are often claimed as trade- marks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the appro- priate companies for more complete information regarding trademarks and registration. This book is printed on acid-free paper. ∞ Copyright © 2002 by Rashi Gupta. All rights reserved. Published by Wiley Publishing, Inc., New York. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copy- right Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: PERMREQ @ WILEY.COM. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold with the understanding that the publisher is not engaged in professional services. If professional advice or other expert assistance is required, the services of a competent professional person should be sought. Library of Congress Cataloging-in-Publication Data: ISBN: 0471-21975-4 Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Printed in the United States of America. 10 9 8 7 6 5 4 3 2 1 TEAM LinG - Live, Informative, Non-cost and Genuine! Introduction xi Scenario xxiii Chapter 1 An Introduction to Python 1 Getting Started 1 Understanding Requirements 2 Determine Requirements of the University 2 Obtain Python and Its Documentation 3 Determine the System Requirements 4 Install Python 5 Start Python in Different Execution Modes 7 Summary 12 Chapter 2 Getting Started with Python 13 Getting Started 14 Writing Your First Python Program 14 Comments 15 Python as a Calculator 16 Using Variables in Python 16 Variables 17 Assigning Values to Variables 18 Standard Types 19 Identifiers and Keywords 39 Memory Management 40 Create a Sequence to Store All the Names of the Students 42 Write the Code to Display the Names of the Students 42 Contents v TEAM LinG - Live, Informative, Non-cost and Genuine! Declare a Dictionary of Student Purchases with the Names of the Students as the Key 43 Write the Code to Display the Student Purchases 43 Save and Execute the Code 43 Verify the Details 44 Summary 44 Chapter 3 Intrinsic Operations and Input/Output 47 Getting Started 48 Using Input/Output Features and Intrinsic Operations for Data Types in Python 48 Identify the Variables to Be Used 49 Accepting User Input 49 Formatting the Output 50 Introduction to Intrinsic Operations 55 Intrinsic Operations for Numeric Data Types 57 Intrinsic Operations for Strings 60 Intrinsic Operations for Lists and Tuples 66 Write the Code 71 Execute the Code 71 Summary 73 Chapter 4 Programming Basics 75 Getting Started 76 Conditional Operators 76 Order of Precedence of Operators 82 Using Programming Constructs 83 Identify the Control and Loop Statements to Be Used 84 Write the Code 94 Execute the Code 95 Summary 97 Chapter 5 Functions 99 Getting Started 100 Using Functions 100 Functions 101 Scope of Variables 118 Identify the Functions to Be Used 119 Write the Code 119 Execute the Code 121 Summary 122 Chapter 6 Modules 123 Getting Started 124 Using Modules 124 Modules 124 Packages 135 Identify the Modules to Be Used 136 vi Contents TEAM LinG - Live, Informative, Non-cost and Genuine! Write the Code 137 Execute the Code 139 Summary 140 Chapter 7 Files 141 Getting Started 141 Using File Objects 142 Identify the Functions and Methods to Be Used 142 Write the Code to Store Course Details to the File 154 Execute the Code 155 Verify the Solution 155 Summary 156 Chapter 8 Object-Oriented Programming 157 Getting Started 158 Introducing OOP 158 Components of OOP 159 Benefits of OOP 160 Using Classes 161 Identify the Classes to Be Defined 162 Identifying the Class Objects 163 Identifying the Classes to Be Inherited and Their Objects 170 Identify the Methods to Be Overridden 173 Write the Code 182 Execute the Code 189 Summary 190 Chapter 9 Exception Handling 193 Getting Started 193 Handling Exceptions 194 Identify the Type of Error and Where the Error Occurs 196 Identify the Mechanism of Trapping the Exception 200 Identify the Location for the Code for Handling the Exception to Be Written 209 Write the Code for Handling the Exception 209 Save and Execute the Code 210 Summary 210 Chapter 10 CGI Programming 213 Getting Started 213 Internet Basics 214 World Wide Web 217 Web Browsers 217 Hypertext Transfer Protocol (HTTP) 220 Revising HTML 221 Client-Side versus Server-Side Scripting 227 An Introduction to CGI 229 Contents vii TEAM LinG - Live, Informative, Non-cost and Genuine! Writing CGI Applications 231 Write the Code for the HTML Form to Accept Data from the User 231 Write the CGI Program in Python to Generate the Results Page 232 Write the CGI Program to Generate Both the Form and Results Pages 236 Execute the Code 237 Summary 239 Chapter 11 Database Programming 241 Getting Started 241 Database Management 242 Introduction to MySQL 243 Working with MySQL 246 Accessing a Database from a Python Script 254 Identify the Elements of the Table That Stores Registration Details 256 Identify the Steps for Connecting to the Database 256 Write the Code to Create a Table in the Database 259 Write the Code to Insert the Registration Details into the Table Created 260 Execute the Code to Create the Table in the Database 261 Execute the Code to Insert Data into the Table 261 Verify the Data in the Database 263 Summary 264 Chapter 12 Network Programming 267 Getting Started 267 Client/Server Architecture 268 Network Programming 269 Using Sockets 272 Identify the Sockets to Be Used 272 Write the Code to Run on the IT Department Computer 287 Write the Code to Run on the Admission Office Computer 288 Execute the Code Created for the IT Department Computer 289 Execute the Code Created for the Admission Office Computer 290 Verify that Data Has Been Saved to a File in the IT Department Computer 292 Summary 292 Chapter 13 Multithreaded Programming 297 Getting Started 297 Single-Threaded Applications 298 Threading in Python 299 viii Contents TEAM LinG - Live, Informative, Non-cost and Genuine! Creating Multithreaded Applications 300 Identify the Class and the Methods to Create a Multithreaded Application 300 Write Code for the Server 308 Write the Code for the Client 309 Execute the Code Created for the Server 310 Execute the Code Created for the Client 311 Summary 313 Chapter 14 Advanced Web Programming 315 Getting Started 316 Creating Web Servers 316 Accessing URLs 323 Creating Advanced CGI Applications 328 Identify the Elements of the Web Page for Entering Assignment Details and Uploading the File 328 Identify the Methodology for Uploading the File 329 Identify the Methodology for Storing User Information 330 Write the Code for the CGI Script 335 Execute the CGI Script 339 Summary 340 Chapter 15 GUI Programming with Tkinter 343 Getting Started 343 Introduction to Tkinter 344 Creating a GUI Application 347 Identify the Components of the User Interface 348 Identify the Tkinter Widgets to Design the User Interface 348 Write the Code for the User Interface 360 Execute the Code 362 Summary 364 Appendix A Distributing COM Objects 365 Basics of COM 365 The Binary Standard 367 COM Interfaces 369 Binding 370 Python and COM 371 Creating COM Clients 371 Creating COM Servers 373 Index 377 Contents ix TEAM LinG - Live, Informative, Non-cost and Genuine! [...]... five stable versions Python 1. 5.2 was released in April 19 99 Python 1. 6 was made available to the public in September 2000 and has major new features and enhancements over Python 1. 5.2 Python 2.0, released in October 2000, was more of a transition from Python 1. 6 Python 2 .1. 1, released in July 20 01, was mainly a bug fix release for Python 2 .1 The final release of the latest version, Python 2.2, was released... migrating from Python 1. 5.2 to 2.0 can use Python 1. 6 Programmers looking for improved features, such as Python s model of objects and classes, improved multiple inheritance, new iteration interface, and new and improved modules, should use Python 2.2 You can find all the latest information about Python on the Python official Web site or the Pythonlabs Web site The links are as follows: http://www .python. org... Introduction to Python Table 1. 3 Software Specifications for Using Python SOFTWARE SPECIFICATION Operating system Linux 7 .1, Windows 2000 Server, and Windows NT Server Web server Apache 1. 3 .19 -5, (IIS 5.0 for Windows) RDBMS My SQL 3.23.36 -1 Web browser Netscape 4.76 GNU C++ For Windows NT/2000 Python Version 2.2a4 Install Python As mentioned earlier, Python distribution is available for a wide variety of platforms... —rebuild python2 .2-2.2b1-2.src.rpm Windows Installation On Windows, you can install Python by running Python- XXX.exe, where XXX is Python s latest release On Windows, double-clicking the file will launch the Installation Wizard, as shown in Figure 1. 1 After installing Python, if you want to install PythonWin and PythonCOM software also, double-click the win32all-YYY.exe file Each version of Python has... features of both compiled and interpreted languages Let’s discuss in detail why Python is considered an interpreted language Python programs can be executed at the interpreter in command-line mode and script mode In command-line mode, you type Python statements, and the interpreter prints the result $ python Python 2.2a4 (#2, Nov 2 20 01, 11 :00:25) GCC 2.96 200007 31 (Red Hat Linux 7 .1 2.96- 81) ] on Linux2... be downloaded from www.winzip.com To run Python, the system requirements are as shown in Table 1. 2 You can choose from a host of software platforms to run Python For the development of this book, the software configuration shown in Table 1. 3 is used Table 1. 2 Hardware Specifications for Using Python HARDWARE SPECIFICATION Processor Pentium, 200 MHz RAM 64 MB, 12 8 MB (Recommended) TEAM LinG - Live, Informative,... The result of the product can, however, be sold or distributed in any manner Users and Application Areas of Python Python is an advanced scripting language that is being used in various areas Some of the areas where Python is being used are the following: s s Gluing together large software components These large software components can be written in C, C++, or Java s s Creating prototypes of an application... features of both an interpreted and a scripting language History of Python Python is directly derived from the scripting language ABC, which was mainly used for teaching purposes in the 19 80s by a small number of people Python s development was triggered by the need to develop tools to automate monotonous and timeconsuming tasks Guido van Rossum is the creator of Python He started work on Python in late 19 89... of Python along with a hoard of Java classes A complete discussion on JPython is out of the scope of this book Some of its salient features are as follows: s s JPython provides a scripting environment for Java development s s JPython generates a truly object-oriented programming environment s s An application written in JPython can access Java classes directly and can integrate them with its own JPython... University ߜ Download Python and its documentation ߜ Determine the system requirements ߜ Install Python ߜ Start Python in different execution modes Determine Requirements of the University Before deciding on the software application and hardware platforms to use for the previous scenario, let’s understand the requirements of the University (see Table 1. 1) Obtain Python and Its Documentation Python is currently . to Be Used 11 9 Write the Code 11 9 Execute the Code 12 1 Summary 12 2 Chapter 6 Modules 12 3 Getting Started 12 4 Using Modules 12 4 Modules 12 4 Packages 13 5 Identify the Modules to Be Used 13 6 vi Contents TEAM. Started with Python 13 Getting Started 14 Writing Your First Python Program 14 Comments 15 Python as a Calculator 16 Using Variables in Python 16 Variables 17 Assigning Values to Variables 18 Standard. File 15 4 Execute the Code 15 5 Verify the Solution 15 5 Summary 15 6 Chapter 8 Object-Oriented Programming 15 7 Getting Started 15 8 Introducing OOP 15 8 Components of OOP 15 9 Benefits of OOP 16 0 Using

Ngày đăng: 09/08/2014, 16:20

TỪ KHÓA LIÊN QUAN