Programming in Python 3

Similar documents
PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

JAVASCRIPT FOR PROGRAMMERS

The Unified Modeling Language User Guide

Digital System Design with SystemVerilog

Rails AntiPatterns. Chad Pytel. Best Practice Ruby on Rails Refactoring. Tammer Saleh. AAddison-Wesley

Quality Code. Software Testing Principles, Practices, and Patterns. Stephen Vance. AAddison-Wesley

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

Framework Design Guidelines

Cloud Computing and SOA Convergence in Your Enterprise

Database Concepts. David M. Kroenke UNIVERSITATSBIBLIOTHEK HANNOVER

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

The Power of Events. An Introduction to Complex Event Processing in Distributed Enterprise Systems. David Luckham

[CHAPTER] 1 INTRODUCTION 1

Prelude to Programming

^l^s^^^^^^^^^^s^^^ ^.1^L^ gs *^gs (s^s^^^^s^^ ^S^^^^ls

Maya Python. for Games and Film. and the Maya Python API. A Complete Reference for Maya Python. Ryan Trowbridge. Adam Mechtley ELSEVIER

Application Programming

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. AAddison-Wesley

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. .~Addison-Wesley

The Java Tutorial. A Short Course on the Basics. Raymond Gallardo. Sowmya Kannan. AAddison-Wesley. Sharon Biocca Zakhour.

LATEX. Leslie Lamport. Digital Equipment Corporation. Illustrations by Duane Bibby. v ADDISON-WESLEY

ony Gaddis Haywood Community College STARTING OUT WITH PEARSON Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Fit for Developing Software

PTN-102 Python programming

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

Python INTRODUCTION: Understanding the Open source Installation of python in Linux/windows. Understanding Interpreters * ipython.

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu

\ Smart Client 0" Deploymentwith v^ ClickOnce

World Wide Web PROGRAMMING THE PEARSON EIGHTH EDITION. University of Colorado at Colorado Springs

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

Objects First with Java

Programming with POSIX Threads

DATABASE SYSTEM CONCEPTS

Refactoring HTML. Improving the Design of Existing Web Applications. Elliotte Rusty Harold. TT rvaddison-wesley

Visual C# Tony Gaddis. Haywood Community College STARTING OUT WITH. Piyali Sengupta. Third Edition. Global Edition contributions by.

Domain-Specific. Languages. Martin Fowler. AAddison-Wesley. Sydney Tokyo. With Rebecca Parsons

Programming Wireless Devices with the Java 2 Platform, Micro Edition

Part I Basic Concepts 1

Essentials of Database Management

Elements Of Programming Interviews In Python The Insiders Guide

Data Science with Python Course Catalog

IPHONE FOR PROGRAMMERS: AN APP-DRIVEN APPROACH

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

DB2 SQL Tuning Tips for z/os Developers

PYTHON TRAINING COURSE CONTENT

Developer's HTML5. Cookbook. AAddison-Wesley. Chuck Hudson. Tom Leadbetter. Upper Saddle River, NJ Boston Indianapolis San Francisco

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

Opengl Programming On Mac Os X Architecture Performance

Table of Contents. Preface... xxi

CLASSIC DATA STRUCTURES IN JAVA

Essentials. Oracle Solaris Cluster. Tim Read. Upper Saddle River, NJ Boston Indianapolis San Francisco. Capetown Sydney Tokyo Singapore Mexico City

Core Java Volume Ii Advanced Features 10th Edition

A Document Preparation System. User's Guide and Reference Manual. Leslie Lamport

Access ComprehGnsiwG. Shelley Gaskin, Carolyn McLellan, and. Nancy Graviett. with Microsoft

Secure Coding in C and C++

Data Structures and Abstractions with Java

PROBLEM SOLVING USING JAVA WITH DATA STRUCTURES. A Multimedia Approach. Mark Guzdial and Barbara Ericson PEARSON. College of Computing

Systems:;-'./'--'.; r. Ramez Elmasri Department of Computer Science and Engineering The University of Texas at Arlington

THE AVR MICROCONTROLLER AND EMBEDDED SYSTEMS. Using Assembly and С

FUNDAMENTALS OF. Database S wctpmc. Shamkant B. Navathe College of Computing Georgia Institute of Technology. Addison-Wesley

ECLIPSE RICH CLIENT PLATFORM

Workbook for C++ THIRD EDITION. Yedidyah Langsam, Ph.D. Brooklyn College of the City University of New York. Custom Publishing

Introductory logic and sets for Computer scientists

Introduction... ix. Chapter 1: Exploring Fundamental Programming Concepts... 1

Fundamentals of. Database Systems. Shamkant B. Navathe. College of Computing Georgia Institute of Technology PEARSON.

Integrated Approach. Operating Systems COMPUTER SYSTEMS. LEAHY, Jr. Georgia Institute of Technology. Umakishore RAMACHANDRAN. William D.

Effective Stl 50 Specific Ways To Improve Your Use Of The... Effective Stl: 50 Specific Ways To Improve The Use Of The...

Search Engines Information Retrieval in Practice

ECLIPSE MODELING PROJECT

CJT^jL rafting Cm ompiler

C for Electronic Engineering

Network Programming With Go Essential Skills For Using And Securing Networks

Django with Python Course Catalog

Python The Definitive Guide To Learning Python Programming

Agile Principles, Patterns, and Practices in C#

Introduction to Python

MECHATRONICS. William Bolton. Sixth Edition ELECTRONIC CONTROL SYSTEMS ENGINEERING IN MECHANICAL AND ELECTRICAL PEARSON

Business Driven Data Communications

MACHINES AND MECHANISMS

Webgurukul Programming Language Course

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

This course is designed for anyone who needs to learn how to write programs in Python.

Programming for Data Science Syllabus

Coding for Penetration

C++ Primer, Fifth Edition

Elements Of Programming Interviews In Java The Insiders Guide

Real-Time Systems and Programming Languages

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Python Scripting for Computational Science

DATA AND COMPUTER COMMUNICATIONS

PYTHON CONTENT NOTE: Almost every task is explained with an example

Logic and its Applications

The Designer's Guide to VHDL Second Edition

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

An Introduction to Programming with IDL

Data Structures and Abstractions with Java

Intermediate Python 3.x

Transcription:

Programming in Python 3 A Complete Introduction to the Python Language Mark Summerfield.4.Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sydney Tokyo Singapore Mexico City

Contents Introduction 1 Chapter I. Rapid Introduction to Procedural Programming 7 Creating and Running Python Programs 7 Python's "Beautiful Heart" 12 Piece #1: Data Types 12 Piece #2: Object References 14 Piece #3: Collection Data Types 16 Piece #4: Logical Operations 19 Piece #5: Control Flow Statements 23 Piece #6: Arithmetic Operators 28 Piece #7: Input/Output 31 Piece #8: Creating and Calling Functions 34 Examples 36 bigdigits.py 36 generate_grid.py 39 Summary 42 Exercises 44 Chapter 2. Data Types 47 Identifiers and Keywords 47 Integral Types 50 Integers 51 Booleans 53 Floating-Point Types 54 Floating-Point Numbers 55 Complex Numbers 58 Decimal Numbers 59 Strings 61 Comparing Strings 63 Slicing and Striding Strings 64 String Operators and Methods 67 vii

String Formatting with the str.formato Method 74 Character Encodings 85 Examples 88 quadratic.py 88 csv2html.py 90 Summary 95 Exercises 97 Chapter 3. Collection Data Types 99 Sequence Types 99 Tuples 100 Named Tuples 103 Lists 104 Set Types 112 Sets 112 Frozen Sets 116 Mapping Types 117 Dictionaries 118 Default Dictionaries 126 Iterating and Copying Collections 127 Iterators and Iterable Operations and Functions 128 Copying Collections 136 Examples 138 generate_usernames.py 138 statistics.py 142 Summary 146 Exercises 147 Chapter 4. Control Structures and Functions 149 Control Structures 149 Conditional Branching 149 Looping 151 Exception Handling 153 Catching and Raising Exceptions 153 Custom Exceptions 158 Custom Functions 161 Names and Docstrings 166 Argument and Parameter Unpacking 167 Accessing Variables in the Global Scope 170 viii

Lambda Functions 172 Assertions 173 Example: make_html_skeleton.py 175 Summary 181 Exercise 182 Chapter 5. Modules 185 Modules and Packages 185 Packages 189 Custom Modules 192 Overview of Python's Standard Library 202 String Handling 202 Command-Line Programming 204 Mathematics and Numbers 205 Times and Dates 205 Algorithms and Collection Data Types 207 File Formats, Encodings, and Data Persistence 208 File, Directory, and Process Handling 211 Networking and Internet Programming 214 XML 216 Other Modules 217 Summary 219 Exercise 220 Chapter 6. Object-Oriented Programming 223 The Object-Oriented Approach 224 Object-Oriented Concepts and Terminology 225 Custom Classes 228 Attributes and Methods 228 Inheritance and Polymorphism 233 Using Properties to Control Attribute Access 236 Creating Complete and Fully Integrated Data Types 238 Custom Collection Classes 251 Creating Classes That Aggregate Collections 251 Creating Collection Classes Using Aggregation 258 Creating Collection Classes Using Inheritance 265 Summary 272 Exercises 274 ix

Chapter 7. File Handling 277 Writing and Reading Binary Data 282 Pickles with Optional Compression 282 Raw Binary Data with Optional Compression 285 Writing and Parsing Text Files 294 Writing Text 295 Parsing Text 296 Parsing Text Using Regular Expressions 299 Writing and Parsing XML Files 302 Element Trees 302 DOM (Document Object Model) 306 Manually Writing XML 309 Parsing XML with SAX (Simple API for XML) 310 Random Access Binary Files 313 A Generic BinaryRecordFile Class 314 Example: The BikeStock Module's Classes 322 Summary 326 Exercises 327 Chapter 8. Advanced Programming Techniques 329 Further Procedural Programming 330 Branching Using Dictionaries 330 Generator Expressions and Functions 331 Dynamic Code Execution and Dynamic Imports 334 Local and Recursive Functions 341 Function and Method Decorators 346 Function Annotations 350 Further Object-Oriented Programming 353 Controlling Attribute Access 353 Functors 357 Context Managers 359 Descriptors 362 Class Decorators 367 Abstract Base Classes 370 Multiple Inheritance 377 Metaclasses 380 Functional-Style Programming 384 Partial Function Application 387

Example: Valid.py 388 Summary 390 Exercises 392 Chapter 9. Processes and Threading 395 Delegating Work to Processes 396 Delegating Work to Threads 400 Example: A Threaded Find Word Program 401 Example: A Threaded Find Duplicate Files Program 404 Summary 409 Exercises 410 Chapter 10. Networking 413 Creating a TCP Client 414 Creating a TCP Server 420 Summary 427 Exercises 427 Chapter 11. Database Programming 431 DBM Databases 432 SQL Databases 436 Summary 443 Exercise 444 Chapter 12. Regular Expressions 445 Python's Regular Expression Language 446 Characters and Character Classes 446 Quantifiers 447 Grouping and Capturing 450 Assertions and Flags 451 The Regular Expression Module 455 Summary 464 Exercises 465 Chapter 13. Introduction to GUI Programming 467 Dialog-Style Programs 470 Main-Window-Style Programs 476 Creating a Main Window 477 Creating a Custom Dialog 488 Summary 491 xi

Exercises 491 Epilogue 493 Index 495 xli