Python Cookbook (3rd edition) Chinese version pdf

Source: Internet
Author: User
Tags class definition time zones cpu usage

: Network Disk Download

Content Introduction· · · · · ·

"Python Cookbook (3rd edition) Chinese version" describes the Python application in various areas of the use of techniques and methods, its topics cover the data structure and algorithms, strings and text, numbers, dates and times, iterators and generators, files and I/O, data encoding and processing, functions, Classes and objects, metaprogramming, modules and packages, networking and web programming, concurrency, utility scripting and system management, testing, debugging and exceptions, C language extensions, and more.

This book covers many of the common problems in Python applications and presents a common solution. The book contains a lot of practical programming skills and sample code, and in the Python 3.3 environment tested, can be easily applied to the actual project. In addition, the Chinese version of Python Cookbook (3rd edition) also explains in detail how the solution works and why it works.

The Python Cookbook (3rd edition) Chinese version is ideal for Python programmers with a certain programming foundation to read the reference.

Author profile ...

David Beazley is an independent software developer and book author who lives in Chicago. His main work lies in programming tools, providing customized software development services, and teaching programming practices to software developers, scientists and engineers. His most well-known work is in the Python programming language, where he has created several open-source packages (such as Swig and ply) and is the author of the award-winning book Python Essential reference. He also has extensive experience in C, C + + and system programming under assembly language.

Brain K. Jones is a system administrator at Princeton University's computer department.

Catalog/Directory
1th chapter data structure and algorithm 1
1.1 Splitting a sequence into a separate variable 1
1.2 Decomposing elements from an arbitrary length of an iterative object 3
1.3 Save last N elements 5
1.4 Finding the largest or smallest n elements 7
1.5 Implementing the Priority Queue 9
1.6 Mapping keys to multiple values in the dictionary 11
1.7 Keep the dictionary in order 13
1.8 Dictionary-related Computational issues 14
1.9 Finding the same point in two dictionaries 15
1.10 Remove duplicates from the sequence and keep the order between elements unchanged 17
1.11 To name a slice 18
1.12 Finding the most frequently occurring element in a sequence 20
1.13 Sort the dictionary list by public key 22
1.14 Sorting objects that do not natively support comparison operations 23
1.15 Grouping records by field 25
1.16 filtering elements in a sequence 26
1.17 extracting a subset from a dictionary 29
1.18 mapping names to elements of a sequence 30
1.19 conversion and conversion of data at the same time 33
1.20 merging multiple mappings into a single map 34
Chapter 2nd string and text 37
2.1 Splitting a string for any number of delimiters 37
2.2 Text match at the beginning or end of a string 38
2.3 Using shell wildcard characters to do string matching 40
2.4 Matching and finding of text patterns 42
2.5 Finding and replacing text 45
2.6 Finding and replacing text in a case-insensitive manner 47
2.7 Defining a regular expression that implements the shortest match 48
2.8 Regular expressions to write multiline patterns 49
2.9 Uniform representation of Unicode text as canonical form 50
2.10 Using regular expressions to process Unicode characters 52
2.11 Remove unwanted characters from a string 53
2.12 Text filtering and cleanup 54
2.13 Align text string 57
2.14 String joins and merges 59
2.15 Interpolation for variable names in a string 62
2.16 reformatting the text with a fixed number of columns 64
2.17 working with HTML and XML entities in text 66
2.18 Text Participle 67
2.19 writing a simple recursive descent parser 70
2.20 performing a text operation on a byte string 80
Chapter 3rd number, date and time 83
3.1 Rounding a number 83
3.2 Performing accurate decimal calculations 85
3.3 Formatted output for numeric values 87
3.4 Dealing with binary, octal, and hexadecimal numbers 89
3.5 Packaging and unpacking large integers from a byte string 90
3.6 Complex number Operation 92
3.7 Handling Infinity and Nan 94
3.8 Calculation of fractions 96
3.9 Handling Large Array Calculations 97
3.10 Computation of matrices and linear algebra 101
3.11 Random Selection 103
3.12 Time Conversion 105
3.13 Calculation last week 5 of 107
3.14 Finding the date range of the month 108
3.15 Converting a string to a date 110
3.16 Handling date issues that involve time zones 112
4th iterator and Generator 114
4.1 Manually accessing elements in an iterator 114
4.2 Delegate Iteration 115
4.3 Creating a new iteration pattern with the generator 116
4.4 Implementing the Iteration Protocol 118
4.5 Reverse Iteration 121
4.6 Defining a generator function with extra states 122
4.7 Slicing operations on Iterators 123
4.8 Skipping the previous element in an iterator object 124
4.9 Iteration all possible combinations or permutations 127
4.10 iterating over a sequence as an index-value pair 129
4.11 iterating over multiple sequences at the same time 131
4.12 Iterating in different containers 133
4.13 Creating a pipeline to process data 134
4.14 Flattening a sequence of nested types 137
4.15 Merge multiple ordered sequences, then iterate over the entire ordered sequence 139
4.16 replacing a while loop with an iterator 140
5th. File and I/O 142
5.1 Read and write text data 142
5.2 Redirecting output to a file 145
5.3 Finish printing with a different delimiter or line end character 145
5.4 Read and write binary data 146
5.5 Write operations on files that are not already present 149
5.6 Performing I/O operations on a string 150
5.7 Read and write compressed data files 151
5.8 iterating over a fixed-size record 152
5.9 reading binary data into a volatile buffer 153
5.10 Memory mappings for binary files 155
5.11 Processing Path name 157
5.12 Detecting whether a file exists 158
5.13 getting a list of directory contents 159
5.14 bypass file name encoding 161
5.15 Printing a file name that cannot be decoded 162
5.16 Add or modify the encoding for a file that is already open 164
5.17 writing byte data to a text file 166
5.18 wrapping an existing file descriptor as a file object 167
5.19 Creating temporary files and directories 169
5.20 Communication with the serial port 171
5.21 serialization of Python objects 172
The 6th Chapter data encoding and processing 177
6.1 Read and write CSV data 177
6.2 Reading and writing JSON data 181
6.3 Parsing a simple XML document 186
6.4 Parsing large XML files incrementally 188
6.5 Converting a dictionary to XML 192
6.6 Parsing, modifying, and rewriting XML 194
6.7 Parsing XML documents with namespaces 196
6.8 Interacting with a relational database 198
6.9 encode and decode hexadecimal digits 201
6.10 BASE64 encoding and decoding 202
6.11 Read and write arrays of binary structures 203
6.12 read nested and variable-size binary structures 207
6.13 Data aggregation and statistics 218
7th Chapter Function 221
7.1 Writing a function that can accept any number of parameters 221
7.2 Writing a function that accepts only keyword arguments 223
7.3 Attaching metadata information to function parameters 224
7.4 Returning multiple values from a function 225
7.5 Defining a function with default parameters 226
7.6 Defining anonymous or inline functions 229
7.7 Binding the value of a variable in an anonymous function 230
7.8 Allow callable objects with n parameters to be called with fewer arguments 232
7.9 replacing a class with a single method with a function 235
7.10 carrying additional states in the callback function 236
7.11 Inline callback function 240
7.12 Accessing variables defined within a closure 242
Chapter 8th class and Object 246
8.1 Modifying the string representation of an instance 246
8.2 Output format for custom strings 248
8.3 Enabling an object to support context Management Protocol 249
8.4 How to save memory when creating a large number of instances 251
8.5 encapsulating a name in a class 252
8.6 Creating a manageable property 254
8.7 Calling method 259 in the parent class
8.8 extending a property in a subclass 263
8.9 Creating a new form of class property or instance property 267
8.10 ability to have lazy evaluation of properties 271
8.11 simplifying the initialization of data structures 274
8.12 defining an interface or abstract base class 278
8.13 Implementing a data model or type system 281
8.14 Implementing the Custom container 287
8.15 access to delegate properties 291
8.16 defining multiple constructors in a class 296
8.17 do not create an instance by calling Init 298
8.18 extending class definitions with Mixin technology 299
8.19 implementing an object with a state or a state machine 305
8.20 call the method on the object, and the method name is given as a string 311
8.21 implementing the Visitor pattern 312
8.22 Implementing a non-recursive visitor pattern 317
8.23 managing memory in a circular data structure 324
8.24 let the class support the comparison operation 327
8.25 creating a Cache instance 330
Chapter 9th meta-Programming 335
9.1 Add a wrapper to the function 335
9.2 How to save metadata for a function when authoring adorners 337
9.3 Unpacking the Adorner 339
9.4 An adorner that defines an acceptable parameter 341
9.5 An adorner that defines a property that can be modified by the user 342
9.6 Define an adorner that can receive optional parameters 346
9.7 using adorners to enforce type checking on function parameters 348
9.8 Defining adorners in a class 352
9.9 defining the adorner as class 354
9.10 The adorner acts on the class and static methods 357
9.11 writing adorners Adding parameters to the wrapped function 359
9.12 using adorners to define a class definition patch 362
9.13 using a meta-class to control the creation of an instance 364
9.14 get the definition order of class properties 367
9.15 Define a meta-class that can accept optional parameters 370
9.16 Mandatory specification of a parameter signature on *args and **kwargs 372
9.17 enforcing encoding conventions in classes 375
9.18 defining a class programmatically 378
9.19 initializing class members at the time of definition 382
9.20 using function annotations to implement method overloading 384
9.21 Avoiding Duplicate attribute methods 391
9.22 Defining the context Manager in a simple way 393
9.23 performing code with local side effects 395
9.24 parsing and parsing python source code 398
9.25 decomposition of Python source code into bytecode 402
10th Module and Package 406
10.1 Organize the modules into bundles by hierarchy 406
10.2 Precise control of the import of all symbols 407
10.3 Importing sub-modules in a package with a relative name 408
10.4 Splitting a module into multiple files 410
10.5 Let the code under each directory import under a unified namespace 413
10.6 Reload Module 415
10.7 Making a directory or zip file a running script 416
10.8 reading a data file in a package 417
10.9 Adding a table of contents to Sys.path 418
10.10 using the name given in the string to import the module 420
10.11 loading the module from the remote machine using the import Hook 421
10.12 patching a module when it is loaded 439
10.13 Install the package for yourself only 441
10.14 Creating a new Python environment 442
10.15 Publishing a custom package 444
11th. Network and web programming 446
11.1 Interacting with HTTP services in the form of a client 446
11.2 Creating a TCP server 450
11.3 Creating a UDP server 454
11.4 The range of IP addresses generated from the CIDR address 456
11.5 Creating a simple, restful interface based on the rest style 458
11.6 using XML-RPC to implement a simple remote procedure call 463
11.7 communication between different interpreters 466
11.8 Implementing a Remote procedure call 468
11.9 Verifying client identities in a simple way 472
11.10 Adding SSL support for network services 474
11.11 passing socket file descriptors between processes 481
11.12 Understanding Event-driven I/O 486
11.13 sending and receiving large arrays 493
12th Chapter 496 Concurrent
12.1 Starting and Stopping threads 496
12.2 Determine if thread has started 499
12.3 Inter-thread communication 503
12.4 Lock the critical Section 508
12.5 Avoiding Deadlocks 511
12.6 Save thread-specific State 515
12.7 Creating a thread pool 517
12.8 implementation of simple parallel programming 521
12.9 How to circumvent the Gil-imposed restrictions 525
12.10 Defining an actor task 528
12.11 Implementing Publisher/Subscriber message Patterns 532
12.12 using generators as an alternative to threading 536
12.13 polling multiple thread queues 544
12.14 Loading daemons on Unix 547
13th. Practical Scripting and system administration 552
13.1 using redirects, pipelines, or input files as input to a script 552
13.2 terminating the program and displaying error messages 553
13.3 parsing command-line options 554
13.4 Provide password input prompt at run time 557
13.5 getting the terminal size 558
13.6 Execute external command and get output 558
13.7 copying or moving files and directories 560
13.8 Creating and reconciling a package archive file 562
13.9 finding files by name 563
13.10 reading a configuration file 565
13.11 Adding a log record to a script 568
13.12 Adding a log record to a library 571
13.13 Creating a stopwatch timer 573
13.14 setting limits for memory and CPU usage 575
13.15 loading a Web browser 576
14th test, Debug and exception 578
14.1 Testing the output sent to the StdOut 578
14.2 patching objects in unit tests 579
14.3 Detecting abnormal conditions in unit tests 583
14.4 Logging The test results as a log to a file 585
14.5 Skip the test or expect the test result to fail 586
14.6 Handling multiple Exceptions 587
14.7 Capturing all exceptions 589
14.8 Creating a Custom exception 591
14.9 responding to another exception by throwing an exception 593
14.10 re-throws the previous exception 595
14.11 emitting a warning message 596
14.12 Debugging Basic program crash issues 598
14.13 Performance analysis of the program and timing statistics 600
14.14 Make your program run faster 603
15th C language Extension 610
15.1 using cTYPES to access C code 612
15.2 writing a simple C language Extension module 618
15.3 Writing an expandable function that operates an array 622
15.4 managing opaque pointers in the C extension Module 625
15.5 Defining and exporting the C API 628 in the extension module
15.6 Calling Python from C 633
15.7 release of Gil 639 in the C expansion module
15.8 mixed use of threads in C and Python environments 639
15.9 using Swig to wrap C code 640
15.10 using Cython to wrap C code 646
15.11 using Cython to efficiently manipulate arrays 652
15.12 Converting a function pointer to a callable object 657
15.13 passing null-terminated strings to C library 659
15.14 passing Unicode strings to C library 663
15.15 converting C strings to Python 667
15.16 dealing with a C string with an indeterminate encoding method 669
15.17 passing the file name to the C extension Module 672
15.18 passing open files to the C extension Module 673
15.19 reading a file-type object in C 674
15.20 accessing an Iterator object from C 677
15.21 Troubleshooting Segment Errors 678
Appendix A supplementary reading 680

: Network Disk Download

Python Cookbook (3rd edition) Chinese version pdf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.