Core Python Programming Wesley J. Chun

Transcription

Safari Core Python ProgrammingShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python ProgrammingSee All TitlesCore Python ProgrammingWesley J. ChunPublisher: Prentice Hall PTRFirst Edition December 14, 2000ISBN: 0-13-026036-3, 816 pagesBuy Print VersionFront MatterTable of ContentsAbout the AuthorExamples New to Python? This is the developer's guide to Pythondevelopment! Learn the core features of Python as well as advanced topicssuch as regular expressions, multithreaded programming,Web/Internet and network development, GUI developmentwith Tk(inter) and more Also includes features found in the new Python 1.6 and 2.0releases CD-ROM: Complete Python distributions (source code,documentation, and various binaries) plus all example scriptsin the bookPython is an Internet and systems programming language that issoaring in popularity in today's fast-paced software developmentenvironment, and no wonder: it's simple (yet robust), object-oriented(yet can be used as a procedural language), extensible, scalable andfeatures an easy to learn syntax that is clear and concise. Pythoncombines the power of a compiled object language like Java and C with the ease of use and rapid development time of a scriptinglanguage. In fact, its syntax is so easy to understand that you are morelikely to pick it up faster than any of the other popular scriptinglanguages in use today!In Core Python Programming, Internet software engineer andtechnical trainer Wesley Chun provides intermediate and experienceddevelopers all they need to know to learn Python-fast. Like all CoreSeries books, Core Python Programming delivers hundreds ofindustrial-strength code snippets and examples, all targeted atprofessional developers who want to leverage their existing skills! Inparticular, Core Python Programming presents numerous interactiveexamples that can be entered into the Python interpreter right in frontof you! Finally, we present a chapter that shows you step-by-step howto extend Python using C or C . Python syntax and style Development and Run-time Environments Objects and Python memory management Standard data types, methods, and c (1 of 3) [6/2/2002 12:12:49 AM]

Safari Core Python Programming Loops and conditionals Files and Input/Output Exceptions and error handling Functions, scope, arguments, and functional programming Importing modules and module attributes Object-oriented Programming with classes, methods, andinstances Callable Objects Extending PythonCoverage of the Python standard module library and client-serverapplication development includes comprehensive introductions to thefollowing topics in Python programming: Regular expressions TCP/IP and UDP/IP Network programming using sockets Operating system interface GUI development with Tk using Tkinter Multithreaded programming Interactive Web/CGI/Internet applications Executing code in a restricted environment Inheritance, type emulation, operator overloading, anddelegation in an OOP environmentFinally, we provide an introduction to the new features introduced inPython 1.6. These include Unicode string support, the new functioninvocation syntax which lets the caller provide a tuple of positionalarguments and/or a dictionary of keyword arguments, and the newstring methods. We also provide a glimpse into features that will onlybe found in the newer 2.0 release.Every Core Series book: DEMONSTRATES how to write commercial-quality code FEATURES dozens of programs and examples! FOCUSES on the features and functions most important to realdevelopers PROVIDES objective, unbiased coverage of cutting-edgetechnologies-no hype!Core Python Programming delivers: Coverage of the core parts of the Python language Real-world insights for developing Web/Internet, network,multithreaded and GUI applications Tables and charts detailing Python modules, built-in functions,operators, and oc (2 of 3) [6/2/2002 12:12:49 AM]

Safari Core Python Programming Code snippets to try live with Python's interactive interpreter,hammering the concepts home Extensive code examples-including several complete sampleapplicationsCD-ROM includes complete Python source code and documentationdistributions for Unix/Linux along with binaries for Windows andMacintosh platforms plus source code for all examples in the book.Delivered for Maurice lingSwap Option Available: 7/15/2002Last updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTR 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?hidetoc (3 of 3) [6/2/2002 12:12:49 AM]

Safari Core Python ProgrammingShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python ProgrammingSee All TitlesCore Python ProgrammingLibrary of Congress Cataloging-in-Publication DateChun, WesleyCore python / Wesley. Chun.p. cm.Includes bibliographical references and index.ISBN 0-13-026036-31. Python (Computer program language) I. TitleQA76.73.P98 C48 2000005.13'3--dc21 00-047856Copyright Information 2001 Prentice Hall PTRPrentice-Hall, IncUpper Saddle River, NJ 07458The publisher offers discounts on this book when ordered in bulk quantities.For more information, contactCorporate Sales Department,Prentice Hall PTROne Lake StreetUpper Saddle River, NJ 07458Phone: 800-382-3419; FAX: 201-236-7141E-mail (Internet): corpsales@prenhall.comAll products or services mentioned herein are the trademarks or service marks of their respectivecompanies or organizations.All rights reserved. No part of this book may be reproduced, in any form or by any means,without permission in writing from the publisher Printed in the United States of America10 9 8 7 6 5 4 3 2 1Prentice-Hall International (UK) Limited, Londonhttp://safari.oreilly.com/main.asp?bookname 0130260363&mode 3 (1 of 2) [6/2/2002 12:13:44 AM]

Safari Core Python ProgrammingPrentice-Hall of Australia Pty. Limited, SydneyPrentice-Hall Canada Inc., TorontoPrentice-Hall Hispanoamericana, S.A., MexicoPrentice-Hall of India Private Limited, New DelhiPrentice-Hall of Japan, Inc., TokyoPearson Education P.T.E., Ltd.To my parents,who taught me that everybody is different.And to my wife,who lives with someone who is different.Delivered for Maurice lingSwap Option Available: 7/15/2002Last updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTR 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&mode 3 (2 of 2) [6/2/2002 12:13:44 AM]

Safari Core Python ProgrammingShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python ProgrammingCore Python ProgrammingWelcome to Python!Style:Technical, Yet Easy ReadingAuthor's Experience with PythonBook ContentsPart I : Core PythonChapter 1 —Welcome to Python!Chapter 2 —Getting StartedChapter 3 —Syntax and StyleChapter 4 —Python ObjectsChapter 5 —NumbersChapter 6 —Sequences: Strings, Lists, and TuplesChapter 7 —DictionariesChapter 8 —Conditionals and LoopsChapter 9 —Files and Input/OutputChapter 10 —Errors and ExceptionsChapter 11 —FunctionsChapter 12 —ModulesChapter 13 —Classes and OOPChapter 14 —Execution EnvironmentPart II : Advanced TopicsChapter 15 —Regular ExpressionsChapter 16 —Network Programming with SocketsChapter 17 —Multithreaded ProgrammingChapter 18 —GUI Programming with TkinterChapter 19 —Web ProgrammingChapter 20 —Extending PythonOptional SectionsConventionsBook SupportAcknowledgementsI: CORE PYTHON1. Welcome to Python!What Is Python?History of PythonFeatures of PythonObtaining PythonObtaining PythonInstalling PythonRunning PythonPython DocumentationComparing PythonJPython and Some n.asp?bookname 0130260363&mode 1 (1 of 6) [6/2/2002 12:13:55 AM]See All Titles

Safari Core Python Programming2. Getting StartedProgram Output, the print Statement, and "Hello World!"Program Input and the raw input() Built-in FunctionCommentsOperatorsVariables and AssignmentNumbersStringsLists and TuplesDictionariesCode Blocks Use Indentationif Statementwhile Loopfor Loop and the range() Built-in FunctionFiles and the open() Built-in FunctionErrors and ExceptionsFunctionsClassesModulesExercises3. Syntax and StyleStatements and SyntaxVariable AssignmentIdentifiersBasic Style GuidelinesMemory ManagementFirst Python ApplicationExercises4. Python ObjectsPython ObjectsStandard TypesOther Built-in TypesInternal TypesStandard Type OperatorsStandard Type Built-in FunctionsCategorizing the Standard TypesUnsupported TypesExercises5. NumbersIntroduction to NumbersIntegersFloating Point Real NumbersComplex NumbersOperatorsBuilt-in FunctionsRelated ModulesExercises6. Sequences: Strings, Lists, and TuplesSequencesStringsStrings and OperatorsString-only me 0130260363&mode 1 (2 of 6) [6/2/2002 12:13:55 AM]

Safari Core Python ProgrammingBuilt-in FunctionsString Built-in MethodsSpecial Features of StringsRelated ModulesSummary of String HighlightsListsOperatorsBuilt-in FunctionsList Type Built-in MethodsSpecial Features of ListsTuplesTuple Operators and Built-in FunctionsSpecial Features of TuplesRelated Modules*Shallow and Deep CopiesExercises7. DictionariesIntroduction to DictionariesOperatorsBuilt-in FunctionsBuilt-in MethodsDictionary KeysExercises8. Conditionals and Loopsif statementelse Statementelif (a.k.a. else-if ) Statementwhile Statementfor Statementbreak Statementcontinue Statementpass Statementelse Statement Take TwoExercises9. Files and Input/OutputFile ObjectsFile Built-in Function [ open() ]File Built-in MethodsFile Built-in AttributesStandard FilesCommand-line ArgumentsFile SystemFile ExecutionPersistent Storage ModulesRelated ModulesExercises10. Errors And ExceptionsWhat Are Exceptions?Exceptions in PythonDetecting and Handling Exceptions*Exceptions as Strings*Exceptions as Classeshttp://safari.oreilly.com/main.asp?bookname 0130260363&mode 1 (3 of 6) [6/2/2002 12:13:55 AM]

Safari Core Python ProgrammingRaising ExceptionsAssertionsStandard Exceptions*Creating ExceptionsWhy Exceptions (Now)?Why Exceptions at All?Exceptions and the sys ModuleRelated ModulesExercises11. FunctionsWhat Are Functions?Calling FunctionsCreating FunctionsPassing FunctionsFormal ArgumentsPositional ArgumentsDefault ArgumentsWhy Default Arguments?Default Function Object Argument ExampleVariable-length ArgumentsNon-keyword Variable Arguments (Tuple)Keyword Variable Arguments (Dictionary)Calling Functions with Variable Argument ObjectsFunctional ProgrammingAnonymous Functions and lambdaBuilt-in Functions: apply(), filter(), map(), reduce()* apply()Lines 1 - 4Lines 6 - 7Lines 9 - 28Lines 30-41filter()map()reduce()Variable Scope*RecursionExercises12. ModulesWhat are Modules?Modules and FilesNamespacesImporting ModulesImporting Module AttributesModule Built-in FunctionsPackagesOther Features of ModulesExercises13. Classes and OOPIntroductionObject-oriented ProgrammingClassesClass asp?bookname 0130260363&mode 1 (4 of 6) [6/2/2002 12:13:55 AM]

Safari Core Python ProgrammingInstance AttributesBinding and Method InvocationCompositionSubclassing and DerivationInheritanceBuilt-in Functions for Classes, Instances, and Other ObjectsType vs. Classes/InstancesCustomizing Classes with Special MethodsPrivacyDelegationRelated Modules and DocumentationExercises14. Execution EnvironmentCallable ObjectsCode ObjectsExecutable Object Statements and Built-in FunctionsExecuting Other (Python) ProgramsExecuting Other (Non-Python) ProgramsRestricted ExecutionTerminating ExecutionRelated ModulesExercisesII: Advanced Topics15. Regular ExpressionsIntroduction/MotivationSpecial Symbols and Characters for REsREs and PythonRegular Expression AdventuresExercises16. Network ProgrammingIntroductionSockets: Communication EndpointsNetwork Programming in PythonRelated ModulesExercises17. Multithreaded ProgrammingIntroduction/MotivationThreads and ProcessesThreads and Pythonthread Modulethreading ModuleExercises18. GUI Programming with TkinterIntroductionTkinter and Python ProgrammingTkinter ExamplesRelated Modules and Other GUIsExercises19. Web ain.asp?bookname 0130260363&mode 1 (5 of 6) [6/2/2002 12:13:55 AM]

Safari Core Python ProgrammingWeb Surfing with Python: Creating Simple Web ClientsAdvanced Web ClientsCGI: Helping Web Servers Process Client DataBuilding CGI ApplicationAdvanced CGIWeb (HTTP) ServersRelated ModulesExercises20. Extending PythonIntroduction/MotivationRelated TopicsExercisesA.Answers to Selected ExercisesB.Other Reading and ReferencesOther Printed ReferencesOnline ReferencesC.Python Operator SummaryD.What's New in Python 2.0?Delivered for Maurice lingSwap Option Available: 7/15/2002Last updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTR 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&mode 1 (6 of 6) [6/2/2002 12:13:55 AM]

Safari Core Python Programming - Welcome to Python!Show TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python!See All TitlesMake Note BookmarkCONTINUE 1098032071132043232151142055147045010064Welcome to Python!Welcome to the wonderful world of Python! As a professional or student with workingknowledge of another high-level programming language, this text was made for you in yourefforts to jump straight into Python with as little overhead as possible. The goal of this bookis to provide text that flows in a conversational style littered with examples to highlight yourpath towards Python programming.At the time of publication, Python 2.0 was just released, so you will definitely have the latestand greatest. The supplementary CD-ROM has the three most recent versions of Python:1.5.2, 1.6, and 2.0, not to mention the most recent release of the Java version of the Pythoninterpreter, JPython (a.k.a. Jython).Delivered for Maurice lingSwap Option Available: 7/15/2002Last updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&cnode 1 [6/2/2002 12:14:02 AM]CONTINUE

Safari Core Python Programming - Style:Technical, Yet Easy ReadingShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python! Style:Technical, Yet Easy Reading BACKMake Note BookmarkSee All TitlesCONTINUE nical, Yet Easy ReadingRather than strictly a "beginners'" book or a pure, hard-core computer science referencebook, my instructional experience indicates that an easy-to-read, yet technically-orientedbook serves our purpose the best, and that is to get you up-to-speed on Python as quickly aspossible, so that you can apply it to your tasks post haste. We will introduce conceptscoupled with appropriate examples to expedite the learning process. At the end of eachchapter you will find numerous exercises to reinforce some of the concepts and ideasacquired in your reading.After the obligatory introduction to Python, but before heading to the core of the language,we take a "quick plunge" into Python with the "Getting Started" chapter. The intention of thischapter is for those who wish to temporarily dispense of formal reading and get their handsdirty with Python immediately. If you do not wish to travel this path, you may proceed asnormal to the next set of chapters, an introduction to Python objects. Python's primitive datatypes, numbers, strings, lists, tuples, and dictionaries make up the next three chapters.Python's error-handling capability is extremely useful to both the programmer and the user,and we address that topic in a separate chapter. Finally, the largest parts of the Python "core"we cover will be functions, modules, and classes each in its own chapter. The final chapterof the text provides insight on how Python may be extended. The last section of the book is amini-reference guide in the appendix. There we spill the beans on the core modules of thestandard library, highlight the operators and built-in operators and functions for the Pythontypes, provide solutions to selected exercises, and conclude with a small glossary of terms.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 3 [6/2/2002 12:14:06 AM]CONTINUE

Safari Core Python Programming - Author's Experience with PythonShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python! Author's Experience with Python BACKMake Note BookmarkSee All TitlesCONTINUE 1098032071132043232151142054013214112194Author's Experience with PythonI discovered Python several years ago at a company called Four11. At the time, the companyhad one major product, the Four11.com White Page directory service. Python was being usedto design the Rocketmail web-based email service that would eventually one day evolve intowhat is Yahoo!Mail today.In addition to the use of C , much of the controlling software and web front-end were donecompletely in Python. I participated in work done on the Yahoo!Mail address book andspellchecker. Since then, Python's appearance has spread to other Yahoo! sites, includingPeople Search, Yellow Pages, and Maps and Driving Directions, just to name a few.Although Python was new to me at the time, it was fairly easy to pick up; much simpler thanother languages that I have learned in the past. The scarcity of the number of textbooks at thetime led me to primarily use the Library Reference and Quick Reference Guide as my toolsin learning, and also led to the motivation of the book you are reading right now.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 4 [6/2/2002 12:14:13 AM]CONTINUE

Safari Core Python Programming - Book ContentsShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python! Book Contents BACKSee All TitlesMake Note BookmarkCONTINUE 1098032071132043232151142054010123187057Book ContentsThis book is divided into two main sections. The first part, taking up about two-thirds of thetext, gives you treatment of the "core" part of the language, and the second part provides aset of various advanced topics to show what you can build using Python.Python is everywhere—sometimes it is amazing to discover who is using Python and whatthey are doing with it—and although we would have loved to produce additional chapters onsuch topics as Databases (RDBMSs, SQL, etc.), CGI Processing with HTMLgen, XML,Numerical/Scientific Processing, Visual and Graphics Image Manipulation, and Zope, theresimply wasn't enough time to develop these topics into their own chapters. However, we arecertainly glad that we were at least able to provide you with a good introduction to many ofthe key areas of Python development.Here is a chapter-by-chapter guide:Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 5 [6/2/2002 12:14:17 AM]CONTINUE

Safari Core Python Programming - Part I : Core PythonShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python! Part I : Core Python BACKSee All TitlesMake Note BookmarkCONTINUE 1098032071132043232152007053194127194185Part I: Core PythonDelivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 6 [6/2/2002 12:15:46 AM]CONTINUE

Safari Core Python Programming - Chapter 1 —Welcome to Python!Show TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming Welcome to Python! Chapter 1 —Welcome to Python! BACKMake Note BookmarkSee All TitlesCONTINUE 1098032071132043232152007053207247062206Chapter 1—Welcome to Python!We begin by introducing Python to you, its history, features, benefits, etc., as well as how toobtain and install Python on your system.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 7 [6/2/2002 12:15:50 AM]CONTINUE

Safari Core Python Programming - 1. Welcome to Python!Show TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming 1. Welcome to Python! BACKSee All TitlesMake Note BookmarkCONTINUE 1098032071132043232153133123250218056043Chapter 1. Welcome to Python!Chapter Topics What is Python, Its History and Features Where to Obtain Python How to Install and Run Python Python Documentation Comparing PythonOur introductory chapter provides some background on what Python is, where it came from,and what some of its "bullet points" are. Once we have stimulated your interest andenthusiasm, we describe how you can obtain Python and get it up and running on yoursystem. Finally, the exercises at the end of the chapter will make you comfortable with usingPython, both in the interactive interpreter and also in creating scripts and executing them.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&cnode 35 [6/2/2002 12:16:05 AM]CONTINUE

Safari Core Python Programming - What Is Python?Show TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming 1. Welcome to Python! What Is Python? BACKSee All TitlesMake Note BookmarkCONTINUE 1098032071132043232153133123246053224125What Is Python?Python is an uncomplicated and robust programming language that delivers both the powerand complexity of traditional compiled languages along with the ease-of-use (and then some)of simpler scripting and interpreted languages. You'll be amazed at how quickly you'll pickup the language as well as what kind of things you can do with Python, not to mention thethings that have already been done. Your imagination will be the only limit.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 37 [6/2/2002 12:16:09 AM]CONTINUE

Safari Core Python Programming - History of PythonShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming 1. Welcome to Python! History of Python BACKSee All TitlesMake Note BookmarkCONTINUE 1098032071132043232153133122188194035063History of PythonWork on Python began in late 1989 by Guido van Rossum, then at CWI in the Netherlands,and eventually released for public distribution in early 1991. How did it all begin? Innovativelanguages are usually born from one of two motivations: a large well-funded research projector general frustration due to the lack of tools that were needed at the time to accomplishmundane and/or time-consuming tasks, many of which could be automated.At the time, van Rossum was a researcher with considerable language design experiencewith the interpreted language ABC, also developed at CWI, but he was unsatisfied with itsability to be developed into something more. Some of the tools he envisioned were forperforming general system administration tasks, so he also wanted access to the power ofsystem calls that were available through the Amoeba distributed operating system. Althoughan Amoeba-specific language was given some thought, a generalized language made moresense, and late in 1989, the seeds of Python were sown.Delivered for Maurice lingSwap Option Available: 7/15/2002 BACKLast updated on 9/14/2001Core Python Programming, 2002 Prentice Hall PTRMake Note Bookmark 2002, O'Reilly & Associates, Inc.http://safari.oreilly.com/main.asp?bookname 0130260363&snode 38 [6/2/2002 12:16:14 AM]CONTINUE

Safari Core Python Programming - Features of PythonShow TOC FramesAll BooksSearchMy Desktop Account Log Out Subscription HelpProgramming Core Python Programming 1. Welcome to Python! Features of Python BACKMake Note BookmarkSee All TitlesCONTINUE 1098032071132043232153133122184040075052Features of PythonAlthough practically a decade in age, Python is still somewhat relatively new to the generalsoftware development industry. We should, however, use caution with our use of the word"relatively," as a few years seem like decades when developing on "Internet time."When people ask, "What is Python?" it is difficult to say any one thing. The tendency is towant to blurt out all the things that you feel Python is in one breath. Python is(fill-in-the-blanks here). Just what are some of those blanks? For your sanity, we willelucidate on each here one at a time.High-levelIt seems that with every generation of languages, we move to a higher level. Assembly was agodsend for those who struggled with machine code, then came FORTRAN, C, and Pascal,all of which took computing to another plane and created the software development industry.These languages then evolved into the current compiled systems languages C and Java.And further still we climb, with powerful, system-accessible, interpreted scripting languageslike Tcl, Perl, and Python. Each of these languages has higher-level data structures thatreduce the "framework" development time which was once required. Useful types likePython's lists (resizeable arrays) and dictionaries (hash tables) are built into the language.Providing these crucial building blocks encourages their use and minimizes developmenttime as well as code size, resulting in more readable code. Implementing them in C iscomplicated and often frustrating due to the necessities of using structures and pointers, notto mention repetitious if some forms of the same data structures require implementation forevery large project. This initial setup is mitigated somewhat with C and its use oftemplates, but still involves work that may not be directly related to the application thatneeds to be developed.Object-orientedObject-oriented programming (OOP) adds another dimension to structured and procedurallanguages where data and logic are discrete elements of programming. OOP allows forassociating specific behaviors, characteristics, and/or capabilities with the data that theyexecute on or are representative of. The object-oriented nature of Python was part of itsdesign from the very beginning. Other OO scripting languages include SmallTalk, theoriginal Xerox PARC language that started it all, and Netscape's JavaScript.ScalablePython is often compared to batch or Unix shell scripting languages. Simple shell scriptshandle simple tasks. They grow (indefinitely) in length, but not truly in depth. There is littlecode-reusability and you are confined to small projects with shell scripts. In fact, even smallprojects may lead to large and unwieldy scripts. Not so with Python, where you can growhttp://safari.oreilly.com/main.asp?bookname 0130260363&snode 39 (1 of 4) [6/2/2002 12:16:20 AM]

Safari Core Python Programming - Features of Pythonyour code from project to project, add other new or existing Python elements, and reuse codeat your whim. Python encourages clean code design, high-level structure, and "packaging" ofmultiple components, all of which deliver the flexibility, consistency, and faster developmenttime required as projects expand in breadth and scope.The term "scalable" is most often applied to measuring hardware throughput and usuallyrefers to additional performance when new hardware is added to a system. We would like todifferentiate this comparison with ours here, which tries to inflect the notion that Pythonprovides basic building blocks on which you can build an application, and as those needsexpand and grow, Python's pluggable and modular architecture allows your project toflourish as well as maintain manageability.ExtensibleAs the amount of Python code increases in your project, you may still be able to organize itlogically due to its dual structured and object-oriented programming environments. Or, betteryet, you can separate your co

Programming Core Python Programming See All Titles Front Matter Table of Contents About the Author Examples Core Python Programming Wesley J. Chun Publisher: Prentice Hall PTR First Edition December 14, 2000 ISBN: 0-13-026036-3, 816 pages Buy Print Version New to Python? This is the