@@ -216,7 +216,7 @@ Python 3.
216216 ** kwargs and manually raising TypeError exceptions.
217217
218218
219- # Chapter 3: Classes and Inheritance
219+ ## Chapter 3: Classes and Inheritance
220220
221221
222222### [ Item 22: Prefer helper classes over bookkeeping with dictionaries and tuples] ( item_22_prefer_helper_classes.py )
@@ -270,6 +270,7 @@ Python 3.
270270- 4 . Only consider using private attributes to avoid naming conflicts with
271271 subclasses that are out of your control.
272272
273+
273274### [ Item 28: Inherit from collections.abc for custom container types] ( item_28_inherit_from_collections_abc.py )
274275- 1 . Inherit directly from Python's container types (like list or dict) for
275276 simple use cases.
@@ -279,6 +280,10 @@ Python 3.
279280 collections.abc to ensure that your classes match required interfaces
280281 and behaviors.
281282
283+
284+ ## Chapter 4: Metaclasses and Attributes
285+
286+
282287### [ Item 29: Use plain attributes instead of get and set methods] ( item_29_use_plain_attributes.py )
283288- 1 . Define new class interfaces using simple public attributes, and avoid set
284289 and get methods.
@@ -289,12 +294,14 @@ Python 3.
289294- 4 . Ensure that @property methods are fast; do slow or complex work using
290295 normal methods.
291296
297+
292298### [ Item 30: Consider @property instead of refactoring attributes] ( item_30_consider_property.py )
293299- 1 . Use @property to give existing instance attributes new functionality.
294300- 2 . Make incremental progress toward better data models by using @property .
295301- 3 . Consider refactoring a class and all call sites when you find yourself
296302 using @property too heavily.
297303
304+
298305### [ Item 31: Use descriptors for reusable @property methods] ( item_31_use_descriptors.py )
299306- 1 . Reuse the behavior and validation of @property methods by defining your
300307 own descriptor classes.
@@ -303,6 +310,7 @@ Python 3.
303310- 3 . Don't get bogged down trying to understand exactly how __ getattribute__
304311 uses the descriptor protocol for getting and setting attributes.
305312
313+
306314### [ Item_32_Use __ getattr__ , __ getattribute__ , and __ setattr__ for lazy attributes] ( item_32_use_getattr.py )
307315- 1 . Use __ getattr__ and __ setattr__ to lazily load and save attributes for an
308316 object.
@@ -313,13 +321,15 @@ Python 3.
313321 methods from super() (i.e., the object class) to access instance
314322 attributes directly.
315323
324+
316325### [ Item 33: Validate subclass with metaclass] ( item_33_validate_subclass.py )
317326- 1 . Use metaclasses to ensure that subclass are well formed at the time they
318327 are defined, before objects of their type are constructed.
319328- 2 . Metaclass have slightly different syntax in Python 2 vs. Python 3.
320329- 3 . The __ new__ method of metaclasses is run after the class statement's
321330 entire body has been processed.
322331
332+
323333### [ Item 34: Register class existence with metaclass] ( item_34_register_class_existence.py )
324334- 1 . Class registration is a helpful pattern for building modular Python
325335 programs.
@@ -328,6 +338,7 @@ Python 3.
328338- 3 . Using metaclass for class registration avoids errors by ensuring that
329339 you never miss a registration call.
330340
341+
331342### [ Item 35: Annotate class attributes with metaclass] ( item_35_annotate_class_attributes.py )
332343- 1 . Metaclass enable you to modify a class's attributes before the class is
333344 fully defined.
@@ -336,6 +347,10 @@ Python 3.
336347- 3 . You can avoid both memory leaks and the weakref module by using
337348 metaclasses along with descriptors.
338349
350+
351+ ## Chapter 5: Concurrency and parallelism
352+
353+
339354### [ Item 36: use subprocess to manage child processes] ( item_36_use_subprocess.py )
340355- 1 . Use the subprocess to run child processes and manage their input and
341356 output streams.
@@ -344,6 +359,7 @@ Python 3.
344359- 3 . Use the timeout parameter with communicate to avoid deadlocks and hanging
345360 child processes.
346361
362+
347363### [ Item 37: Use threads for blocking I/O, avoid for parallelism] ( item_37_use_threads.py )
348364- 1 . Python threads can't bytecode in parallel on multiple CPU cores because
349365 of the global interpreter lock (GIL).
@@ -352,6 +368,7 @@ Python 3.
352368- 3 . Use Python threads to make multiple system calls in parallel. This allows
353369 you to do blocking I/O at the same time as computation.
354370
371+
355372### [ Item 38: Use lock to prevent data races in threads] ( item_38_use_lock.py )
356373- 1 . Even though Python has a global interpreter lock, you're still
357374 responsible for protecting against objects without locks.
@@ -360,6 +377,7 @@ Python 3.
360377- 3 . The lock class in the threading built-in module is Python's standard
361378 mutual exclusion lock implementation.
362379
380+
363381### [ Item 39: Use queue to coordinate work between threads] ( item_39_use_queue.py )
364382- 1 . Pipelines are a great way to organize sequences of work that run
365383 concurrently using multiple Python threads.
@@ -368,6 +386,7 @@ Python 3.
368386- 3 . The Queue class has all of the facilities you need to build robust
369387 pipelines: blocking operations, buffer sizes, and joining.
370388
389+
371390### [ Item 40: Consider coroutines to run many functions concurrently] ( item_40_consider_coroutines.py )
372391- 1 . Coroutines provide an efficient way to run tens of thousands of functions
373392 seemingly at the same time.
@@ -377,6 +396,7 @@ Python 3.
377396 program from its interaction with the surrounding environment.
378397- 4 . Python 2 doesn't support yield from or returning values from generators.
379398
399+
380400### [ Item 41: Consider concurrent.futures for true parallelism] ( item_41_consider+concurrent_futures.py )
381401- 1 . Moving CPU bottlenecks to C-extension modules can be an effective way to
382402 improve performance while maximizing your investment in Python code.
@@ -389,6 +409,10 @@ Python 3.
389409- 4 . The advanced parts of the multiprocessing module should be avoided
390410 because they are so complex.
391411
412+
413+ ## Chapter 6: Built-in Modules
414+
415+
392416### [ Item 42: Define function decorators with functools.wraps] ( item_42_define_function_decorators.py )
393417- 1 . Decorators are Python syntax for allowing one function to modify another
394418 function at runtime.
@@ -397,6 +421,7 @@ Python 3.
397421- 3 . Use the wraps decorator from the functools built-in module when you
398422 define your own decorators to avoid any issues.
399423
424+
400425### [ Item 43: Consider contextlib and with statements for reusable try/finally behavior] ( item_43_consier_contextlib.py )
401426- 1 . The with statement allows you to reuse logic from try/finally blocks and
402427 reduce visual noise.
@@ -406,6 +431,7 @@ Python 3.
406431 with statement. It's useful for letting your code directly access the
407432 cause of the special context.
408433
434+
409435### [ Item 44: Make pickle reliable with copyreg] ( item_44_make_pickle_reliable.py )
410436- 1 . The pickle built-in module is only useful for serializing and
411437 de-serializing objects between trusted programs.
@@ -414,23 +440,27 @@ Python 3.
414440- 3 . Use the copyreg built-in module with pickle to add missing attributes
415441 values, allow versioning of classes, and provide stable import paths.
416442
443+
417444### [ Item 45: Use datetime instead of time for local clocks] ( item_45_use_date_time.py )
418445- 1 . Avoid using the time module for translating between different time zones.
419446- 2 . Use the datetime built-in module along with the pytz module to reliably
420447 convert between times in different time zones.
421448- 3 . Always represent time in UTC and do conversations to local time as the
422449 final step before presentation.
423450
451+
424452### [ Item 46: Use built-in algorithms and data structures] ( item_46_use_built_in_algorithm.py )
425453- 1 . Use Python's built-in modules for algorithms and data structures.
426454- 2 . Don't re-implement this functionality yourself. It's hard to get right.
427455
456+
428457### [ Item 47: Use decimal when precision ia paramount] ( item_47_use_decimal.py )
429458- 1 . Python has built-in types and classes in modules that can represent
430459 practically every type of numerical value.
431460- 2 . The Decimal class is ideal for situations that require high precision and
432461 exact rounding behavior, such as computations of monetary values.
433462
463+
434464### [ Item 48: Know where to find community built modules] ( item_48_communit_built_modules.py )
435465- 1 . The Python Package Index (PyPI) contains a wealth of common packages
436466 that are built and maintained by the Python community.
@@ -439,6 +469,10 @@ Python 3.
439469 yourself for older versions.
440470- 4 . The majority of PyPI modules are free and open source software.
441471
472+
473+ ## Chapter 7: Collaboration
474+
475+
442476### [ Item 49: Write docstrings for every function, class and module] ( item_49_write_docstrings_4_everything.py )
443477- 1 . Write documentation for every module, class and function using
444478 docstrings. Keep them up to date as your code changes.
@@ -450,6 +484,7 @@ Python 3.
450484 raised exception, and other behaviors in the docstring following the
451485 def statement.
452486
487+
453488### [ Item 50: Use packages to organize modules and provide stable APIs] ( item_50_use_packages.py )
454489- 1 . Packages in Python are modules that contain other modules. Packages allow
455490 you to organize your code into separate, non-conflicting namespaces with
@@ -466,6 +501,7 @@ Python 3.
466501- 5 . When collaborating within a single team or on a single codebase, using
467502 __ all__ for explicit APIs is probably unnecessary.
468503
504+
469505### [ Item 51: Define a root exception to insulate callers from APIs] ( item_51_define_a_root_exception.py )
470506- 1 . Defining root exceptions for your modules allows API consumers to
471507 insulate themselves from your API.
@@ -476,6 +512,7 @@ Python 3.
476512- 4 . Intermediate root exceptions let you add more specific types of
477513 exceptions in the future without breaking your API consumers.
478514
515+
479516### [ Item 52: Know how to break circular dependencies] ( item_52_break_circular_dependencies.py )
480517- 1 . Circular dependencies happen when two modules must call into each other
481518 at import time. They can cause your program to crash at startup.
@@ -484,6 +521,7 @@ Python 3.
484521- 3 . Dynamic imports are the simplest solution for breaking a circular
485522 dependency between modules while minimizing refactoring and complexity.
486523
524+
487525### [ Item 53: Use virtual environments for isolated and reproducible dependencies] ( item_53_use_virtual_environments.py )
488526- 1 . Virtual environment allow you to use pip to install many different
489527 versions of the same package on the same machine without conflicts.
@@ -496,7 +534,17 @@ Python 3.
496534 installed separately. The command-line tool is called virtualenv instead
497535 of pyvenv.
498536
499- ### [ ] ( )
537+
538+ ## Chapter 8: Production
539+
540+
541+ ### [ Item 54: Consider module-scoped code to configure deployment environments] ( item_54_consier_module_scoped_code.py )
542+ - 1 . Programs often need to run in multiple deployment environments that each
543+ have unique assumptions and configurations.
544+ - 2 . You can tailor a module's contents to different deployment environments
545+ by using normal Python statements in module scope.
546+ - 3 . Module contents can be the product of any external condition, including
547+ host introspection through the sys and os modules.
500548
501549### [ ] ( )
502550
0 commit comments