深入Python 5.4 版本,中文翻译!

建议使用 zhDiveIntoPyTemplate 文章模板!

-- Zoom.Quiet [2004-08-19 21:52:55]

1. Dive Into Python

20 May 2004

Copyright © 2000, 2001, 2002, 2003, 2004 Mark Pilgrim

This book lives at http://diveintopython.org/. If you're reading it somewhere else, you may not have the latest version.

Permission is granted to copy, distribute, and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in Appendix G, GNU Free Documentation License.

The example programs in this book are free software; you can redistribute and/or modify them under the terms of the Python license as published by the Python Software Foundation. A copy of the license is included in Appendix H, Python license.

1.1. 章节索引

1.1.1. Installing Python

  • /1. Installing Python

  • /1.1. Which Python is right for you?

  • /1.2. Python on Windows

  • /1.3. Python on Mac OS X

  • /1.4. Python on Mac OS 9

  • /1.5. Python on RedHat Linux

  • /1.6. Python on Debian GNU/Linux

  • /1.7. Python Installation from Source

  • /1.8. The Interactive Shell

  • /1.9. Summary

1.1.2. Your First Python Program

  • /2. Your First Python Program

  • /2.1. Diving in

  • /2.2. Declaring Functions

  • /2.2.1. How Python's Datatypes Compare to Other Programming Languages

  • /2.3. Documenting Functions

  • /2.4. Everything Is an Object

  • /2.4.1. The Import Search Path

  • /2.4.2. What's an Object?

  • /2.5. Indenting Code

  • /2.6. Testing Modules

1.1.3. Native Datatypes

1.1.4. The Power Of Introspection

  • /4. The Power Of Introspection

  • /4.1. Diving In

  • /4.2. Using Optional and Named Arguments

  • /4.3. Using type, str, dir, and Other Built-In Functions

  • /4.3.1. The type Function

  • /4.3.2. The str Function

  • /4.3.3. Built-In Functions

  • /4.4. Getting Object References With getattr

  • /4.4.1. getattr with Modules

  • /4.4.2. getattr As a Dispatcher

  • /4.5. Filtering Lists

  • /4.6. The Peculiar Nature of and and or

  • /4.6.1. Using the and-or Trick

  • /4.7. Using lambda Functions

  • /4.7.1. Real-World lambda Functions

  • /4.8. Putting It All Together

  • /4.9. Summary

1.1.5. Objects and Object-Orientation

  • /5. Objects and Object-Orientation

  • /5.1. Diving In

  • /5.2. Importing Modules Using from module import

  • /5.3. Defining Classes

  • /5.3.1. Initializing and Coding Classes

  • /5.3.2. Knowing When to Use self and init

  • /5.4. Instantiating Classes

  • /5.4.1. Garbage Collection

  • /5.5. Exploring UserDict: A Wrapper Class

  • /5.6. Special Class Methods

  • /5.6.1. Getting and Setting Items

  • /5.7. Advanced Special Class Methods

  • /5.8. Introducing Class Attributes

  • /5.9. Private Functions

  • /5.10. Summary

1.1.6. Exceptions and File Handling

1.1.7. Regular Expressions

  • /7. Regular Expressions

  • /7.1. Diving In

  • /7.2. Case Study: Street Addresses

  • /7.3. Case Study: Roman Numerals

  • /7.3.1. Checking for Thousands

  • /7.3.2. Checking for Hundreds

  • /7.4. Using the {n,m} Syntax

  • /7.4.1. Checking for Tens and Ones

  • /7.5. Verbose Regular Expressions

  • /7.6. Case study: Parsing Phone Numbers

  • /7.7. Summary

1.1.8. HTML Processing

  • /8. HTML Processing

  • /8.1. Diving in

  • /8.2. Introducing sgmllib.py

  • /8.3. Extracting data from HTML documents

  • /8.4. Introducing BaseHTMLProcessor.py

  • /8.5. locals and globals

  • /8.6. Dictionary-based string formatting

  • /8.7. Quoting attribute values

  • /8.8. Introducing dialect.py

  • /8.9. Putting it all together

  • /8.10. Summary

1.1.9. XML Processing

1.1.10. Scripts and Streams

  • /10. Scripts and Streams

  • /10.1. Abstracting input sources

  • /10.2. Standard input, output, and error

  • /10.3. Caching node lookups

  • /10.4. Finding direct children of a node

  • /10.5. Creating separate handlers by node type

  • /10.6. Handling command-line arguments

  • /10.7. Putting it all together

  • /10.8. Summary

1.1.11. HTTP Web Services

1.1.12. SOAP Web Services

1.1.13. Unit Testing

1.1.14. Test-First Programming

1.1.15. Refactoring

1.1.16. Functional Programming

1.1.17. Dynamic functions

1.1.18. Performance Tuning

  • /18. Performance Tuning

  • /18.1. Diving in

  • /18.2. Using the timeit Module

  • /18.3. Optimizing Regular Expressions

  • /18.4. Optimizing Dictionary Lookups

  • /18.5. Optimizing List Operations

  • /18.6. Optimizing String Manipulation

1.1.18.1. Summary

  • /18.7. Summary

  • /A. Further reading

  • /B. A 5-minute review

  • /C. Tips and tricks

  • /D. List of examples

  • /E. Revision history

  • /F. About the book

  • /G. GNU Free Documentation License

  • /G.0. Preamble

  • /G.1. Applicability and definitions

  • /G.2. Verbatim copying

  • /G.3. Copying in quantity

  • /G.4. Modifications

  • /G.5. Combining documents

  • /G.6. Collections of documents

  • /G.7. Aggregation with independent works

  • /G.8. Translation

  • /G.9. Termination

  • /G.10. Future revisions of this license

  • /G.11. How to use this License for your documents

  • /H. Python license

  • /H.A. History of the software

  • /H.B. Terms and conditions for accessing or otherwise using Python

  • /H.B.1. PSF license agreement

  • /H.B.2. BeOpen Python open source license agreement version 1

  • /H.B.3. CNRI open source GPL-compatible license agreement

  • /H.B.4. CWI permissions statement and disclaimer

1.2. Wiki小工具

  • 手工加 Wiki 的页面声明太 SB 了!
  • Python 来帮忙!

f=open("DinPy",'r')
s=f.read()
#print s
import re
def wikiName(matchobj):
    return " * [\"/%s\"] "%matchobj.group(0)[:-1]
    
key = re.compile(r"(^\w[.|0-9a-zA-Z]+?)\s",re.M)
r=re.sub(key,wikiName,s)
print r
open("DinPy.wiki",'w').write(r)