Html

Printing 414

Other 414

Chapter 22: Using Curses 415

A Curses Overview 415

Starting Up and Shutting Down 416

Displaying and Erasing Text 416

Reading from the window (screen-scraping) 417

Erasing 418

Refreshing 418

Boxes and lines 418

The window background 418

Example: masking a box 419

Moving the Cursor 420

Getting User Input 421

Reading keys 422

Other keyboard-related functions 422

Fancy characters 422

Reading mouse input 423

Managing Windows 425

Pads 425

Stacking windows 426

Editing Text 426

Using Color 427

Numbering 427

Setting colors 428

Tweaking the colors 428

Example: A Simple Maze Game 428

Chapter 23: Building Simple Command Interpreters 433

Beginning with the End in Mind 433

Understanding the Lepto Language 435

Creating a Lepto Lexical Analyzer 436

The shlex module 436

Putting shlex to work 437

Adding Interactive-Mode Features 440

Using the cmd module 440

Subclassing cmd.Cmd 442

Executing Lepto Commands 445

Chapter 24: Playing Sound 453

Sound File Basics 453

Playing Sounds 454

Playing sound on Windows 454

Playing and recording sound on SunOS 455

Examining Audio Files 456

Reading and Writing Audio Files 456

Reading and writing AIFF files with aifc 457

Reading and writing AU files with sunau 458

Reading and writing WAV files with wave 458

Example: Reversing an audio file 458

Reading IFF chunked data 460

Handling Raw Audio Data 461

Examining a fragment 461

Searching and matching 462

Translating between storage formats 462

Manipulating fragments 463

Chapter 25: Processing Images 467

Image Basics 467

Identifying Image File Types 468

Converting Between Color Systems 469

Color systems 469

Converting from one system to another 470

Handling Raw Image Data 472

Using the Python Imaging Library 472

Retrieving image information 473

Copying and converting images 474

Using PIL with Tkinter 475

Cropping and resizing images 476

Modifying pixel data 476

Other PIL features 480

Chapter 26: Multithreading 481

Understanding Threads 481

Spawning, Tracking, and Killing Threads 482

Creating threads with the thread module 482

Starting and stopping threads with the threading module 483

Thread status and information under threading 484

Finding threads under threading 484

Waiting for a thread to finish 484

Avoiding Concurrency Issues 485

Locking with thread 485

Locking with threading 486

Preventing Deadlock 488

Example: Downloading from Multiple URLs 489

Porting Threaded Code 494

Weaving Threads Together with Queues 495

Technical Note: How Simultaneous Is Simultaneous? 495

For More Information 496

Chapter 27: Debugging, Profiling, and Optimization 497

Debugging Python Code 497

Starting and stopping the debugger 497

Examining the state of things 498

Setting breakpoints 499

Running 500

Aliases 500

Debugging tips 500

Working with docstrings 501

Automating Tests 502

Synching docstrings with code 502

Unit testing 503

Finding Bottlenecks 505

Profiling code 505

Using Profile objects 506

Calibrating the profiler 507

Customizing statistics 507

Common Optimization Tricks 509

Sorting 509

Looping 510

I/O 510

Strings 511

Threads 511

Taking out the Trash—the Garbage Collector 512

Reference counts and Python code 512

Reference counts and C/C++ code 513

Chapter 28: Security and Encryption 515

Checking Passwords 515

Running in a Restricted Environment 516

The rexec sandbox 517

Using a class fortress 520

Creating Message Fingerprints 521

Was this article helpful?

0 0

Post a comment