Python Cookbook(第三版,影印版)
David Beazley, Brian K. Jones
出版时间:2013年12月
页数:687
如果你需要一些帮助来编写基于Python 3的程序,或者想要更新老一些的Python 2代码,这本书就是入场券。这本书包含了用Python 3.3编写和测试过的实例,适合于那些希望专注于新工具和新方法的有经验的Python程序员。
在这本书里,你将找到十多个技术课题的完整实例,涵盖了核心Python语言和多种应用领域的常见任务。每种实例都包含了你可以直接使用在项目中的样例,以及关于这种解决方案如何和为什么可以奏效的讨论。

主题包括:
· 数据结构和算法
· 字符串和文本
· 数字、日期和时间
· 迭代器和生成器
· 文件和I/O
· 数据编码和处理
· 函数
· 类和对象
· 元编程
· 网络和Web编程
· 并发
· 工具集脚本编程和系统管理
· 测试、调试和异常
· C扩展

David Beazley是一名独立软件开发者。他为开发人员、科学家和工程师讲解编程课程。他是《Python Essential Reference》(Addison-Wesley出版社)的作者,并且创作了多个开源的Python包。
Brian K. Jones是普林斯顿大学计算机科学系的系统管理员。
  1. Chapter 1: Data Structures and Algorithms
  2. Unpacking a Sequence into Separate Variables
  3. Unpacking Elements from Iterables of Arbitrary Length
  4. Keeping the Last N Items
  5. Finding the Largest or Smallest N Items
  6. Implementing a Priority Queue
  7. Mapping Keys to Multiple Values in a Dictionary
  8. Keeping Dictionaries in Order
  9. Calculating with Dictionaries
  10. Finding Commonalities in Two Dictionaries
  11. Removing Duplicates from a Sequence while Maintaining Order
  12. Naming a Slice
  13. Determining the Most Frequently Occurring Items in a Sequence
  14. Sorting a List of Dictionaries by a Common Key
  15. Sorting Objects Without Native Comparison Support
  16. Grouping Records Together Based on a Field
  17. Filtering Sequence Elements
  18. Extracting a Subset of a Dictionary
  19. Mapping Names to Sequence Elements
  20. Transforming and Reducing Data at the Same Time
  21. Combining Multiple Mappings into a Single Mapping
  22. Chapter 2: Strings and Text
  23. Splitting Strings on Any of Multiple Delimiters
  24. Matching Text at the Start or End of a String
  25. Matching Strings Using Shell Wildcard Patterns
  26. Matching and Searching for Text Patterns
  27. Searching and Replacing Text
  28. Searching and Replacing Case-Insensitive Text
  29. Specifying a Regular Expression for the Shortest Match
  30. Writing a Regular Expression for Multiline Patterns
  31. Normalizing Unicode Text to a Standard Representation
  32. Working with Unicode Characters in Regular Expressions
  33. Stripping Unwanted Characters from Strings
  34. Sanitizing and Cleaning Up Text
  35. Aligning Text Strings
  36. Combining and Concatenating Strings
  37. Interpolating Variables in Strings
  38. Reformatting Text to a Fixed Number of Columns
  39. Handling HTML and XML Entities in Text
  40. Tokenizing Text
  41. Writing a Simple Recursive Descent Parser
  42. Performing Text Operations on Byte Strings
  43. Chapter 3: Numbers, Dates, and Times
  44. Rounding Numerical Values
  45. Performing Accurate Decimal Calculations
  46. Formatting Numbers for Output
  47. Working with Binary, Octal, and Hexadecimal Integers
  48. Packing and Unpacking Large Integers from Bytes
  49. Performing Complex-Valued Math
  50. Working with Infinity and NaNs
  51. Calculating with Fractions
  52. Calculating with Large Numerical Arrays
  53. Performing Matrix and Linear Algebra Calculations
  54. Picking Things at Random
  55. Converting Days to Seconds, and Other Basic Time Conversions
  56. Determining Last Friday’s Date
  57. Finding the Date Range for the Current Month
  58. Converting Strings into Datetimes
  59. Manipulating Dates Involving Time Zones
  60. Chapter 4: Iterators and Generators
  61. Manually Consuming an Iterator
  62. Delegating Iteration
  63. Creating New Iteration Patterns with Generators
  64. Implementing the Iterator Protocol
  65. Iterating in Reverse
  66. Defining Generator Functions with Extra State
  67. Taking a Slice of an Iterator
  68. Skipping the First Part of an Iterable
  69. Iterating Over All Possible Combinations or Permutations
  70. Iterating Over the Index-Value Pairs of a Sequence
  71. Iterating Over Multiple Sequences Simultaneously
  72. Iterating on Items in Separate Containers
  73. Creating Data Processing Pipelines
  74. Flattening a Nested Sequence
  75. Iterating in Sorted Order Over Merged Sorted Iterables
  76. Replacing Infinite while Loops with an Iterator
  77. Chapter 5: Files and I/O
  78. Reading and Writing Text Data
  79. Printing to a File
  80. Printing with a Different Separator or Line Ending
  81. Reading and Writing Binary Data
  82. Writing to a File That Doesn’t Already Exist
  83. Performing I/O Operations on a String
  84. Reading and Writing Compressed Datafiles
  85. Iterating Over Fixed-Sized Records
  86. Reading Binary Data into a Mutable Buffer
  87. Memory Mapping Binary Files
  88. Manipulating Pathnames
  89. Testing for the Existence of a File
  90. Getting a Directory Listing
  91. Bypassing Filename Encoding
  92. Printing Bad Filenames
  93. Adding or Changing the Encoding of an Already Open File
  94. Writing Bytes to a Text File
  95. Wrapping an Existing File Descriptor As a File Object
  96. Making Temporary Files and Directories
  97. Communicating with Serial Ports
  98. Serializing Python Objects
  99. Chapter 6: Data Encoding and Processing
  100. Reading and Writing CSV Data
  101. Reading and Writing JSON Data
  102. Parsing Simple XML Data
  103. Parsing Huge XML Files Incrementally
  104. Turning a Dictionary into XML
  105. Parsing, Modifying, and Rewriting XML
  106. Parsing XML Documents with Namespaces
  107. Interacting with a Relational Database
  108. Decoding and Encoding Hexadecimal Digits
  109. Decoding and Encoding Base64
  110. Reading and Writing Binary Arrays of Structures
  111. Reading Nested and Variable-Sized Binary Structures
  112. Summarizing Data and Performing Statistics
  113. Chapter 7: Functions
  114. Writing Functions That Accept Any Number of Arguments
  115. Writing Functions That Only Accept Keyword Arguments
  116. Attaching Informational Metadata to Function Arguments
  117. Returning Multiple Values from a Function
  118. Defining Functions with Default Arguments
  119. Defining Anonymous or Inline Functions
  120. Capturing Variables in Anonymous Functions
  121. Making an N-Argument Callable Work As a Callable with Fewer Arguments
  122. Replacing Single Method Classes with Functions
  123. Carrying Extra State with Callback Functions
  124. Inlining Callback Functions
  125. Accessing Variables Defined Inside a Closure
  126. Chapter 8: Classes and Objects
  127. Changing the String Representation of Instances
  128. Customizing String Formatting
  129. Making Objects Support the Context-Management Protocol
  130. Saving Memory When Creating a Large Number of Instances
  131. Encapsulating Names in a Class
  132. Creating Managed Attributes
  133. Calling a Method on a Parent Class
  134. Extending a Property in a Subclass
  135. Creating a New Kind of Class or Instance Attribute
  136. Using Lazily Computed Properties
  137. Simplifying the Initialization of Data Structures
  138. Defining an Interface or Abstract Base Class
  139. Implementing a Data Model or Type System
  140. Implementing Custom Containers
  141. Delegating Attribute Access
  142. Defining More Than One Constructor in a Class
  143. Creating an Instance Without Invoking init
  144. Extending Classes with Mixins
  145. Implementing Stateful Objects or State Machines
  146. Calling a Method on an Object Given the Name As a String
  147. Implementing the Visitor Pattern
  148. Implementing the Visitor Pattern Without Recursion
  149. Managing Memory in Cyclic Data Structures
  150. Making Classes Support Comparison Operations
  151. Creating Cached Instances
  152. Chapter 9: Metaprogramming
  153. Putting a Wrapper Around a Function
  154. Preserving Function Metadata When Writing Decorators
  155. Unwrapping a Decorator
  156. Defining a Decorator That Takes Arguments
  157. Defining a Decorator with User Adjustable Attributes
  158. Defining a Decorator That Takes an Optional Argument
  159. Enforcing Type Checking on a Function Using a Decorator
  160. Defining Decorators As Part of a Class
  161. Defining Decorators As Classes
  162. Applying Decorators to Class and Static Methods
  163. Writing Decorators That Add Arguments to Wrapped Functions
  164. Using Decorators to Patch Class Definitions
  165. Using a Metaclass to Control Instance Creation
  166. Capturing Class Attribute Definition Order
  167. Defining a Metaclass That Takes Optional Arguments
  168. Enforcing an Argument Signature on *args and **kwargs
  169. Enforcing Coding Conventions in Classes
  170. Defining Classes Programmatically
  171. Initializing Class Members at Definition Time
  172. Implementing Multiple Dispatch with Function Annotations
  173. Avoiding Repetitive Property Methods
  174. Defining Context Managers the Easy Way
  175. Executing Code with Local Side Effects
  176. Parsing and Analyzing Python Source
  177. Disassembling Python Byte Code
  178. Chapter 10: Modules and Packages
  179. Making a Hierarchical Package of Modules
  180. Controlling the Import of Everything
  181. Importing Package Submodules Using Relative Names
  182. Splitting a Module into Multiple Files
  183. Making Separate Directories of Code Import Under a Common Namespace
  184. Reloading Modules
  185. Making a Directory or Zip File Runnable As a Main Script
  186. Reading Datafiles Within a Package
  187. Adding Directories to sys.path
  188. Importing Modules Using a Name Given in a String
  189. Loading Modules from a Remote Machine Using Import Hooks
  190. Patching Modules on Import
  191. Installing Packages Just for Yourself
  192. Creating a New Python Environment
  193. Distributing Packages
  194. Chapter 11: Network and Web Programming
  195. Interacting with HTTP Services As a Client
  196. Creating a TCP Server
  197. Creating a UDP Server
  198. Generating a Range of IP Addresses from a CIDR Address
  199. Creating a Simple REST-Based Interface
  200. Implementing a Simple Remote Procedure Call with XML-RPC
  201. Communicating Simply Between Interpreters
  202. Implementing Remote Procedure Calls
  203. Authenticating Clients Simply
  204. Adding SSL to Network Services
  205. Passing a Socket File Descriptor Between Processes
  206. Understanding Event-Driven I/O
  207. Sending and Receiving Large Arrays
  208. Chapter 12: Concurrency
  209. Starting and Stopping Threads
  210. Determining If a Thread Has Started
  211. Communicating Between Threads
  212. Locking Critical Sections
  213. Locking with Deadlock Avoidance
  214. Storing Thread-Specific State
  215. Creating a Thread Pool
  216. Performing Simple Parallel Programming
  217. Dealing with the GIL (and How to Stop Worrying About It)
  218. Defining an Actor Task
  219. Implementing Publish/Subscribe Messaging
  220. Using Generators As an Alternative to Threads
  221. Polling Multiple Thread Queues
  222. Launching a Daemon Process on Unix
  223. Chapter 13: Utility Scripting and System Administration
  224. Accepting Script Input via Redirection, Pipes, or Input Files
  225. Terminating a Program with an Error Message
  226. Parsing Command-Line Options
  227. Prompting for a Password at Runtime
  228. Getting the Terminal Size
  229. Executing an External Command and Getting Its Output
  230. Copying or Moving Files and Directories
  231. Creating and Unpacking Archives
  232. Finding Files by Name
  233. Reading Configuration Files
  234. Adding Logging to Simple Scripts
  235. Adding Logging to Libraries
  236. Making a Stopwatch Timer
  237. Putting Limits on Memory and CPU Usage
  238. Launching a Web Browser
  239. Chapter 14: Testing, Debugging, and Exceptions
  240. Testing Output Sent to stdout
  241. Patching Objects in Unit Tests
  242. Testing for Exceptional Conditions in Unit Tests
  243. Logging Test Output to a File
  244. Skipping or Anticipating Test Failures
  245. Handling Multiple Exceptions
  246. Catching All Exceptions
  247. Creating Custom Exceptions
  248. Raising an Exception in Response to Another Exception
  249. Reraising the Last Exception
  250. Issuing Warning Messages
  251. Debugging Basic Program Crashes
  252. Profiling and Timing Your Program
  253. Making Your Programs Run Faster
  254. Chapter 15: C Extensions
  255. Accessing C Code Using ctypes
  256. Writing a Simple C Extension Module
  257. Writing an Extension Function That Operates on Arrays
  258. Managing Opaque Pointers in C Extension Modules
  259. Defining and Exporting C APIs from Extension Modules
  260. Calling Python from C
  261. Releasing the GIL in C Extensions
  262. Mixing Threads from C and Python
  263. Wrapping C Code with Swig
  264. Wrapping Existing C Code with Cython
  265. Using Cython to Write High-Performance Array Operations
  266. Turning a Function Pointer into a Callable
  267. Passing NULL-Terminated Strings to C Libraries
  268. Passing Unicode Strings to C Libraries
  269. Converting C Strings to Python
  270. Working with C Strings of Dubious Encoding
  271. Passing Filenames to C Extensions
  272. Passing Open Files to C Extensions
  273. Reading File-Like Objects from C
  274. Consuming an Iterable from C
  275. Diagnosing Segmentation Faults
  276. Appendix: Further Reading
  277. Online Resources
  278. Books for Learning Python
  279. Advanced Books
  280. Index
书名:Python Cookbook(第三版,影印版)
国内出版社:东南大学出版社
出版时间:2013年12月
页数:687
书号:978-7-5641-4598-9
原版书书名:Python Cookbook, 3rd Edition
原版书出版商:O'Reilly Media
David Beazley
 
David Beazley是一位独立的软件开发人员,为其他开发人员、科学家以及工程师讲授编程课程。他是Python Essential Reference(Addison-Wesley)一书的作者,已经创建了多个开源的Python包。
 
 
Brian K. Jones
 
Brain K.Jones是普林斯顿大学计算机系的系统管理员。
 
 
The animal on the cover of Python Cookbook, Third Edition is a springhaas (Pedetes capensis), also known as a spring hare. Springhaas are not hares at all, but rather the only member of the family Pedetidae in the order Rodentia. They are not marsupials, but they are vaguely kangaroo-like, with small front legs, powerful hind legs designed for hopping, jumping, and leaping, and long, strong, bushy (but not prehensile) tails used for balance and as a brace when sitting. They grow to be about 14 to 18 inches long, with tails as long as their bodies, and can weigh approximately eight pounds. Springhaas have rich, glossy, tawny, or golden-reddish coats with long, soft fur and white underbellies. Their heads are disproportionately large, and they have long ears (with a flap of skin at the base they can close to prevent sand from getting inside while they are digging) and large, dark brown eyes.

Springhaas mate throughout the year and have a gestation period of about 78 to 82 days. Females generally give birth to only one baby (which stays with its mother until it is approximately seven weeks old) per litter but have three or four litters each year. Babies are born with teeth and are fully furred, with their eyes closed and ears open.

Springhaas are terrestrial and well-adapted for digging, and they tend to spend their days in the small networks of their burrows and tunnels. They are nocturnal and primarily herbivorous, feeding on bulbs, roots, grains, and occasionally insects. While they are foraging, they move about on all fours, but they are able to move 10 to 25 feet in a single horizontal leap and are capable of quick getaways when frightened. Although they are often seen foraging in groups in the wild, they do not form an organized social unit and usually nest alone or in breeding pairs. Springhaas can live up to 15 years in captivity. They are found in Zaire, Kenya, and South Africa, in dry, desert, or semiarid areas, and they are a favorite and important food source in South Africa.
购买选项
定价:98.00元
书号:978-7-5641-4598-9
出版社:东南大学出版社