PYTHON IN A NUTSHELL. O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo. Alex Martelli. Second Edition

Similar documents
JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

JAVA IN A NUTSHELL O'REILLY. David Flanagan. Fifth Edition. Beijing Cambridge Farnham Köln Sebastopol Tokyo

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

[ Team LiB ] Table of Contents Index Reviews Examples Reader Reviews Errata Python in a Nutshell By Alex Martelli

Oracle PL/SQL Programming

Certified The Grinder Testing Professional VS-1165

Windows PowerShell Cookbook

Automating System Administration with Perl

Web Security Testing Cookbook*

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

Programming Flash Communication Server

Hadoop: The Definitive Guide

Java the UML Way: Integrating Object-Oriented Design and Programming

JavaScript Patterns. Stoyan Stefanov. O'REILLY' Beijing Cambridge Farnham Koln Sebastopol Tokyo

Course Structure of Three Year Degree B.A Programme in Computer Application under Semester System of Dibrugarh University (General Programme)

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

INSIDE SERVLETS. Server-Side Programming for the Java Platform. An Imprint of Addison Wesley Longman, Inc.

Programming Social Applications

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

Features of The Grinder 3

USE OF PYTHON AS A SATELLITE OPERATIONS AND TESTING AUTOMATION LANGUAGE

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Hadoop: The Definitive Guide

Learning ios Programming

socketio Documentation

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python


AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

Efficiency of Web Based SAX XML Distributed Processing

Chapter 27 Hypertext Transfer Protocol

LabVIEW Internet Toolkit User Guide

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Preface. Motivation for this Book

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

An introduction to creating JSF applications in Rational Application Developer Version 8.0

ERIE COMMUNITY COLLEGE COURSE OUTLINE A. COURSE TITLE: CS WEB DEVELOPMENT AND PROGRAMMING FUNDAMENTALS

FileMaker Server 15. Custom Web Publishing Guide

Credits: Some of the slides are based on material adapted from

Real time vehicle tracking and driver behaviour monitoring using cellular handset based accelerometer and GPS data

ERIE COMMUNITY COLLEGE COURSE OUTLINE A. COURSE NUMBER CS WEB DEVELOPMENT & PROGRAMMING I AND TITLE:

Dreamweaver CS3 THE MISSING MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Things you didn't know about Python

The POCO C++ Libraries for Device Software Development

Wiley. Automated Data Collection with R. Text Mining. A Practical Guide to Web Scraping and

PROFESSIONAL. Node.js BUILDING JAVASCRIPT-BASED SCALABLE SOFTWARE. Pedro Teixeira WILEY. John Wiley & Sons, Inc.

For Course Details, visit:

Lecture 11 Web Application Security (part 1)

FileMaker Server 14. Custom Web Publishing Guide

Learning Web App Development

Programming 3D Applications with HTML5 and WebGL

... Introduction... 17

Transport Layer Security Protocols

MD Link Integration MDI Solutions Limited

INT322. By the end of this week you will: (1)understand the interaction between a browser, web server, web script, interpreter, and database server.

Java Power Tools. John Ferguson Smart. ULB Darmstadt 1 PI. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

How To Write A Nosql Database In Spring Data Project

Course Description for the Bachelors Degree in Library and Information Science

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

If your organization is not already

Computer Networks 1 (Mạng Máy Tính 1) Lectured by: Dr. Phạm Trần Vũ MEng. Nguyễn CaoĐạt

Programming Language Pragmatics

GUI application set up using QT designer. Sana Siddique. Team 5

ICE Trade Vault. Public User & Technology Guide June 6, 2014

Agent Languages. Overview. Requirements. Java. Tcl/Tk. Telescript. Evaluation. Artificial Intelligence Intelligent Agents

Java Application Developer Certificate Program Competencies

Web application development landscape: technologies and models

Schneps, Leila; Colmez, Coralie. Math on Trial : How Numbers Get Used and Abused in the Courtroom. New York, NY, USA: Basic Books, p i.

Windows Vista The Definitive Guide

Design Notes for an Efficient Password-Authenticated Key Exchange Implementation Using Human-Memorable Passwords

Detailed Table of Contents

Cross-Platform Software Considerations for Internet of Things

Enterprise Application Development In Java with AJAX and ORM

Integrating the Internet into Your Measurement System. DataSocket Technical Overview

Serializing Data with Protocol Buffers. Vinicius Vielmo Cogo Smalltalks, DI, FC/UL. February 12, 2014.

FileMaker Server 9. Custom Web Publishing with PHP

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

Application layer Web 2.0

Online Data Monitoring Framework Based on Histogram Packaging in Network Distributed Data Acquisition Systems

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Efficiency Considerations of PERL and Python in Distributed Processing

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Adding Advanced Caching and Replication Techniques to the Apache Web Server

maximizing IT productivity

Learning Web Design. Third Edition. A Beginner's Guide to (X)HTML, Style Sheets, and Web Graphics. Jennifer Niederst Robbins

Crawl Proxy Installation and Configuration Guide

DEVELOPMENT OF AN ANALYSIS AND REPORTING TOOL FOR ORACLE FORMS SOURCE CODES

sendmail Cookbook Craig Hunt O'REILLY' Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Computer Information Systems Programs. Applied Computer Information Systems Associate in Science Degree and Certificate of Achievement

FileMaker Server 13. Custom Web Publishing with XML

JAVA r VOLUME II-ADVANCED FEATURES. e^i v it;

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Some programming experience in a high-level structured programming language is recommended.

FIFTH EDITION. Oracle Essentials. Rick Greenwald, Robert Stackowiak, and. Jonathan Stern O'REILLY" Tokyo. Koln Sebastopol. Cambridge Farnham.

Transcription:

PYTHON IN A NUTSHELL Second Edition Alex Martelli O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

iii Table of Contents Preface ix Part 1. Getting Started with Python 1. Introduction to Python 3 The Python Language 3 The Python Standard Library and Extension Modules 5 Python Implementations 5 Python Development and Versions 8 Python Resources 9 2. Installation 14 Installing Python from Source Code 14 Installing Python from Binaries 18 Installing Jython 20 Installing IronPython 21 3. The Python Interpreter 22 The python Program 22 Python Development Environments 26 Running Python Programs 28 The jython Interpreter 29 The IronPython Interpreter 30

iv I Tal* of Contents Part II. Core Python Language and Built-ins 4. The Python Language 33 Lexical Structure 33 Data Types 38 Variables and Other References 46 Expressions and Operators 50 Numeric Operations 52 Sequence Operations 53 Set Operations 58 Dictionary Operation 59 The print Statement 61 Control Flow Statements 62 Functions 70 5. Object-Oriented Python 81 Classes and Instances 82 Special Methods 104 Decorators 115 Metaclasses 116 6. Exceptions 121 The try Statement 121 Exception Propagation 126 The raise Statement 128 Exception Objects 129 Custom Exception Classes 132 Error-Checking Strategies 134 7. Modules 139 Module Objects 139 Module Loading 144 Packages 149 The Distribution Utilities (distutils) 150 8. Core Built-ins 153 Built-in Types 154 Built-in Functions 158 The sys Module 168 The copy Module 172 The collections Module 173

Table of Contents 1 v The functional Module 175 The bisect Module 176 The heapq Module 177 The UserDict Module 178 The optparse Module 179 The itertools Module 183 9. Strings and Regular Expressions 186 Methods of String Objects 186 The string Module 191 String Formatting 193 The pprint Module 197 The repr Module 198 Unicode 198 Regular Expressions and the re Module 201 Part III. Python Library and Extension Modules 10. File and Text Operations 215 Other Chapters That Also Deal with Files 215 Organization of This Chapter 215 File Objects 216 Auxiliary Modules for File I/O 224 The StringlO and cstringlo Modules 229 Compressed Files 230 The os Module 240 Filesystem Operations 241 Text Input and Output 256 Richer-Text I/O 258 Interactive Command Sessions 265 Internationalization 269 11. Persistence and Databases 277 Serialization 278 DBM Modules 285 Berkeley DB Interfacing 288 The Python Database API (DBAPI) 2.0 292

vi I Table nf Cnntents 12. Time Operations 302 The time Module 302 The datetime Module 306 The pytz Module 313 The dateutil Module 313 The sched Module 316 The calendar Module 317 The mx.datetime Module 319 13. Controlling Execution 328 Dynamic Execution and the exec Statement 328 Internal Types 331 Garbage Collection 332 Termination Functions 337 Site and User Customization 338 14. Threads and Processes 340 Threads in Python 341 The thread Module 341 The Queue Module 342 The threading Module 344 Threaded Program Architecture 350 Process Environment 353 Running Other Programs 354 The mmap Module 360 15. Numeric Processing 365 The math and cmath Modules 365 The Operator Module 368 Random and Pseudorandom Numbers 370 The decimal Module 372 The gmpy Module 373 16. Array Processing 375 The array Module 375 Extensions for Numeric Array Computation 377 The Numeric Package 378 Array Objects 378 Universal Functions (ufuncs) 399 Auxiliary Numeric Modules 403

Table of Contents I vii 17. Tkinter GUIs 405 Tkinter Fundamentals 406 Widget Fundamentals 408 Commonly Used Simple Widgets 415 Container Widgets 420 Menus 423 The Text Widget 426 The Canvas Widget 436 Layout Management 442 Tkinter Events 446 18. Testing, Debugging, and Optimizing 451 Testing 452 Debugging 461 The warnings Module 471 Optimization 474 Part IV. Network and Web Programming 19. Client-Side Network Protocol Modules 493 URL Access 493 Email Protocols 503 The HTTP and FTP Protocols 506 Network News 511 Telnet 515 Distributed Computing 517 Other Protocols 519 20. Sockets and Server-Side Network Protocol Modules 520 The socket Module 521 The SocketServer Module 528 Event-Driven Socket Programs 533 21. CGI Scripting and Alternatives 545 CGI in Python 546 Cookies 553 Other Server-Side Approaches 557

22. MIME and Network Encodings 561 Encoding Binary Data as Text 561 MIME and Email Format Handling 564 23. Structured Text: HTML 575 The sgmllib Module 576 The htmllib Module 580 The HTMLParser Module 583 The BeautifulSoup Extension 585 Generating HTML 586 24. Structured Text: XML 591 An Overview of XML Parsing 592 Parsing XML with SAX 593 Parsing XML with DOM 598 Changing and Generating XML 606 Part V. Extending and Embedding 25. Extending and Embedding Classic Python 613 Extending Python with Python's C API 614 Extending Python Without Python's C API 645 Embedding Python 647 Pyrex 650 26. Extending and Embedding Jython 655 Importing Java Packages in Jython 656 Embedding Jython in Java 659 Compiling Python into Java 662 27. Distributing Extensions and Programs 666 Python's distutils 666 py2exe 675 py2app 676 cx_freeze 676 Pylnstaller 676 Index 677 viii I Table of Contents