Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is a working draft of a pre-release book. It is available before the published date as part of the Rough Cuts service.
A Fully Revised Edition Featuring New Material on Coroutines, Debugging, Testing, Parsing, String Formatting, and More
Python 3 is the best version of the language yet: It is more powerful, convenient, consistent, and expressive than ever before. Now, leading Python programmer Mark Summerfield demonstrates how to write code that takes full advantage of Python 3’s features and idioms. Programming in Python 3, Second Edition, brings together all the knowledge you need to write any program, use any standard or third-party Python 3 library, and create new library modules of your own.
Summerfield draws on his many years of Python experience to share deep insights into Python 3 development you won’t find anywhere else. He begins by illuminating Python’s “beautiful heart”: the eight key elements of Python you need to write robust, high-performance programs. Building on these core elements, he introduces new topics designed to strengthen your practical expertise–one concept and hands-on example at a time. Coverage includes
Programming in Python 3, Second Edition, serves as both tutorial and language reference. It assumes some prior programming experience, and it is accompanied by extensive downloadable example code–all of it tested with Python 3 on Windows, Linux, and Mac OS X.
List of Tables xv
Introduction 1
Chapter 1: Rapid Introduction to Procedural Programming 9
Creating and Running Python Programs 9
Python’s “Beautiful Heart” 14
Examples 39
Summary 44
Exercises 47
Chapter 2: Data Types 51
Identifiers and Keywords 51
Integral Types 54
Floating-Point Types 58
Strings 65
Examples 94
Summary 102
Exercises 104
Chapter 3: Collection Data Types 107
Sequence Types 107
Set Types 120
Mapping Types 126
Iterating and Copying Collections 138
Examples 148
Summary 156
Exercises 158
Chapter 4: Control Structures and Functions 159
Control Structures 159
Exception Handling 163
Custom Functions 171
Example: make_html_skeleton.py 185
Summary 191
Exercise 192
Chapter 5: Modules 195
Modules and Packages 195
Overview of Python’s Standard Library 212
Summary 230
Exercise 231
Chapter 6: Object-Oriented Programming 233
The Object-Oriented Approach 234
Custom Classes 238
Custom Collection Classes 261
Summary 283
Exercises 285
Chapter 7: File Handling 287
Writing and Reading Binary Data 292
Writing and Parsing Text Files 305
Writing and Parsing XML Files 312
Random Access Binary Files 324
Summary 336
Exercises 337
Chapter 8: Advanced Programming Techniques 339
Further Procedural Programming 340
Further Object-Oriented Programming 363
Functional-Style Programming 395
Example: Valid.py 407
Summary 410
Exercises 411
Chapter 9: Debugging, Testing, and Profiling 413
Debugging 414
Unit Te
