Wrox Home  
Search

Topic: Open Source

Beginning Python: Using Python 2.6 and Python 3.1 (0470414634) cover image

Beginning Python: Using Python 2.6 and Python 3.1

James Payne
ISBN: 978-0-470-41463-7
Paperback
624 pages
February 2010
Other Available Formats: E-book
If you are an instructor, you may request an evaluation copy for this title.
Paperback Version: US $39.99 Add to Cart

About This Title  |  Download Code  |  Errata  |  P2P Forum for This Title

Introduction xxvii

Part I: Dipping Your Toe into Python 1

Chapter 1: Programming Basics and Strings 3

How Programming is Different from Using a Computer 3

The First Steps 5

Beginning to Use Python — Strings 7

Putting Two Strings Together 11

Putting Strings Together in Different Ways 12

Summary 13

Exercises 14

Chapter 2: Numbers and Operators 15

Different Kinds of Numbers 15

Program Files 18

Using Numbers 24

Summary 28

Exercises 29

Chapter 3: Variables — Names for Values 31

Referring to Data — Using Names for Data 31

Using More Built-in Types 34

Other Common Sequence Properties 43

Summary 47

Exercises 48

Part II: Python Language and the Standard Library 49

Chapter 4: Making Decisions 51

Comparing Values — Are They the Same? 51

Doing the Opposite — Not Equal 53

Comparing Values — Which One Is More? 54

Reversing True and False 56

Looking for the Results of More Than One Comparison 56

Repetition 60

Handling Errors 65

Summary 67

Exercises 69

Chapter 5: Functions 71

Putting Your Program into Its Own File 71

Functions: Grouping Code under a Name 73

Layers of Functions 88

Summary 89

Exercises 90

Chapter 6: Classes and Objects 93

Thinking About Programming 93

Defining a Class 96

Summary 107

Exercises 108

Chapter 7: Organizing Programs 111

Modules 112

Packages 118

Modules and Packages 120

Basics of Testing Your Modules and Packages 124

Summary 124

Exercises 125

Chapter 8: Files and Directories 127

File Objects 127

Paths and Directories 131

Exceptions in os 132

Summary 142

Exercises 142

Chapter 9: Other Features of the Language 143

Lambda and Filter: Short Anonymous Functions 143

Map: Short-Circuiting Loops 144

Decisions within Lists — List Comprehension 145

Generating Iterators for Loops 146

Special String Substitution Using Dictionaries 148

Featured Modules 149

Summary 156

Exercises 156

Chapter 10: Building a Module 157

Exploring Modules 157

Creating Modules and Packages 162

Working with Classes 163

Finishing Your Modules 166

Creating a Whole Module 179

Installing Your Modules 183

Summary 187

Exercises 188

Chapter 11: Text Processing 189

Why Text Processing Is So Useful 189

Navigating the File System with the os Module 192

Working with Regular Expressions and the re Module 199

Summary 203

Exercises 204

Part III: Putting Python to Work 205

Chapter 12: Testing 207

Assertions 208

Test Cases and Test Suites 209

Test Fixtures 213

Putting It All Together with Extreme Programming 216

Formal Testing in the Software Life Cycle 224

Summary 225

Chapter 13: Writing a GUI with Python 227

GUI Programming Toolkits for Python 228

Tkinter Introduction 229

Creating GUI Widgets with Tkinter 229

Summary 238

Exercises 238

Chapter 14: Accessing Databases 239

Working with DBM Persistent Dictionaries 240

Working with Relational Databases 245

Using the Python Database APIs 252

Summary 262

Exercises 263

Chapter 15: Using Python for XML 265

What Is XML? 265

What Is a Schema/DTD? 268

Document Type Definitions 268

Schemas 270

XPath 272

HTML as a Subset of XML 272

XML Libraries Available for Python 274

What Is SAX? 274

Why Use SAX or DOM 275

SAX and DOM Parsers Available for Python 276

Intro to XSLT 280

What Is lxml? 280

Element Classes 281

Parsing with lxml 283

Summary 285

Exercises 285

Chapter 16: Network Programming 287

Understanding Protocols 289

Sending Internet E-mail 293

Retrieving Internet E-mail 305

Socket Programming 314

Introduction to Sockets 314

Binding to an External Hostname 316

Other Topics 332

Summary 334

Exercises 335

Chapter 17: Extension Programming with C 337

Extension Module Outline 338

Building and Installing Extension Modules 340

Passing Parameters from Python to C 342

Returning Values from C to Python 345

The LAME Project 346

The LAME Extension Module 350

Using Python Objects from C Code 363

Summary 366

Exercises 366

Chapter 18: Numerical Programming 367

Numbers in Python 368

Mathematics 374

Complex Numbers 378

Arrays 380

Summary 384

Exercises 384

Chapter 19: An Introduction to Django 387

What Are Frameworks and Why Would I Use One? 388

Other Features of Web Frameworks 388

Django — How It All Began 389

Understanding Django’s Architecture 390

Working with Templates 396

Using Templates and Views 398

Creating a Model: Creating an Application 403

Working with Models: Installation 404

Summary 405

Exercises 406

Chapter 20: Web Applications and Web Services 407

REST: The Architecture of the Web 408

HTTP: Real-World REST 411

CGI: Turning Scripts into Web Applications 417

HTML Forms’ Limited Vocabulary 422

Safety When Accessing Form Values 423

Building a Wiki 428

Web Services 441

REST Web Services 442

XML-RPC 456

SOAP 465

Documenting Your Web Service API 472

Choosing a Web Service Standard 478

Web Service Etiquette 479

Summary 480

Exercises 480

Chapter 21: Integrating Java with Python 481

Scripting within Java Applications 482

Comparing Python Implementations 483

Installing Jython 483

Running Jython 484

Running Jython on Your Own 488

Packaging Jython-Based Applications 488

Integrating Java and Jython 489

Testing from Jython 506

Embedding the Jython Interpreter 507

Handling Differences between C-Python and Jython 510

Summary 511

Exercises 512

Part IV: Appendices 513

Appendix A: Answers to the Exercises 515

Appendix B: Online Resources 549

Appendix C: What’s New in Python 3.1 553

Appendix D: Glossary 559

Index 569

Printer-Ready Version   Share This
With you wherever you go: pdf + ePub + kindle -- DRM-free