Cxx

Extension classes 550

Chapter 30: Embedding the Python Interpreter 553

Tracking Reference Counts 553

Types of reference ownership 553

Reference conventions 554

Common pitfalls 555

Using the Abstract and Concrete Object Layers 555

Object layers 556

Working with generic objects 556

Working with Number Objects 558

Any numerical type 558

Integers 560

Longs 560

Floating-point numbers 561

Complex numbers 561

Working with Sequence Objects 561

Any sequence type 562

Strings 563

Lists 564

Tuples 565

Buffers 566

Unicode strings 567

Working with Mapping Objects 569

Functions for any mapping type 569

Dictionaries 570

Using Other Object Types 571

Type 571

None 571

File 571

Module 572

CObjects 574

Creating Threads and Sub-Interpreters 574

Threads 575

Sub-interpreters 576

Handling Errors and Exceptions 576

Checking for errors 577

Signaling error conditions 577

Creating custom exceptions 578

Raising warnings 578

Managing Memory 579

Chapter 31: Number Crunching 581

Using Math Routines 581

Rounding and fractional parts 581

General math routines 582

Logarithms and exponentiation 582

Trigonometric functions 582

Computing with Complex Numbers 583

Generating Random Numbers 583

Random numbers 583

Example: shuffling a deck 585

Random distributions 585

Example: plotting distributions using Monte Carlo sampling 586

Using Arbitrary-Precision Numbers 587

Chapter 32: Using NumPy 589

Introducing Numeric Python 589

Installing NumPy 589

Some quick definitions 590

Meet the array 590

Accessing and Slicing Arrays 590

Contiguous arrays 592

Converting arrays to lists and strings 592

Calling Universal Functions 593

Ufunc destinations 594

Example: editing an audio stream 594

Repeating ufuncs 595

Creating Arrays 597

Array creation functions 597

Seeding arrays with functions 598

Using Element Types 600

Reshaping and Resizing Arrays 600

Using Other Array Functions 601

where(condition,X,Y) 602

swapaxes(array,axis1,axis2) 602

Matrix operations 602

Array Example: Analyzing Price Trends 603

Chapter 33: Parsing and Interpreting Python Code 605

Examining Tracebacks 605

Printing a traceback — print_exc and friends 605

Extracting and formatting exceptions 606

Example: reporting exceptions in a GUI 607

Eating arbitrary exceptions is bad for you 607

Introspection 608

Review: basic introspection 608

Browsing classes 609

Browsing function information 609

Checking Indentation 611

Tokenizing Python Code 611

Example: Syntax-Highlighting Printer 612

Inspecting Python Parse Trees 613

Creating an AST 613

ASTs and sequences 614

Using ASTs 614

Low-Level Object Creation 614

Disassembling Python Code 615

Chapter 34: Creating Worldwide Applications 619

Internationalization and Localization 619

Preparing Applications for Multiple Languages 620

An NLS example 620

What it all means 623

Formatting Locale-Specific Output 624

Changing the locale 624

Locale-specific formatting 625

Properties of locales 626

Chapter 35: Customizing Import Behavior 629

Understanding Module Importing 629

Finding and Loading Modules with imp 631

Importing Encrypted Modules 633

Retrieving Modules from a Remote Source 636

Subclassing Importer 636

Creating the remote Importer 637

Testing the remote Importer 640

Chapter 36: Distributing Modules and Applications 643

Understanding distutils 643

Creating a simple distribution 644

Installing the simple distribution 645

Other distutils Features 647

Distributing packages 647

Including other files 648

Customizing setup 650

Distributing Extension Modules 650

Creating Source and Binary Distributions 651

Source distributions 652

Binary distributions 653

Installers 653

Building Standalone Executables 655

py2exe 655

Freeze 656

Other tools 657

Chapter 37: Windows 661

Using win32all 661

Data types 661

Error handling 662

Finding what you need 662

Example: Using Some Windows APIs 662

Accessing the Windows Registry 664

Accessing the registry with win32all 664

Example: setting the Internet Explorer home page 666

Creating, deleting, and navigating keys 666

Example: recursive deletion of a key 667

Other registry functions 668

Accessing the registry with _winreg 668

Using msvcrt Goodies 669

Console I/O 669

Other functions 670

Chapter 38: UNIX-Compatible Modules 671

Checking UNIX Passwords and Groups 671

Accessing the System Logger 673

Calling Shared Library Functions 675

Providing Identifier and Keyword Completion 675

Retrieving File System and Resource Information 677

File system information 678

Resource usage 678

Resource limits 679

Controlling File Descriptors 680

Handling Terminals and Pseudo-Terminals 681

Interfacing with Sun's NIS "Yellow Pages" 682

Appendix A: Online Resources 685

Appendix B: Python Development Environments 689

Index 701

Was this article helpful?

0 0

Post a comment