The Python Journeyman
Book information
Description
One of Python’s strengths is that it’s approachable and easy to learn, so that almost anyone can learn to write a basic Python program. The Python Journeyman will take you beyond that, beyond the basics. We will lead you through some of the deeper aspects of Python, and give you the skills you need to write great Python programs. The Python Journeyman is the second book in our trilogy covering the core Python language. The material in these books is derived from Sixty North’s popular and battle-tested training courses which have led thousands of programmers on a journey to being productive with Python. Our books, which use Python 3, follow a spiral curriculum: We introduce topics gently and then revisit them on multiple occasions to add the depth required to support your progression as a Python developer. We’ve worked hard to structure the syllabus to avoid forward references. On only a few occasions do we require you to accept techniques on trust, before explaining them later; where we do, it’s to deliberately establish good habits. Table of Contents......Page 3 Errata and Suggestions......Page 8 Conventions Used in This Book......Page 9 Welcome Journeyman!......Page 12 Built-in types: Integers, Floats, Strings, Lists, Dictionaries and Sets......Page 13 Defining classes with methods......Page 14 Unit testing, debugging and deployment......Page 15 Well begun is half done......Page 16 Packages......Page 17 Implementing packages......Page 23 Relative imports......Page 31 __all__......Page 34 Namespace packages......Page 36 Executable directories......Page 38 Executable packages......Page 41 Recommended layout......Page 44 Modules are singletons......Page 45 Summary......Page 46 Review of Functions......Page 49 Functions as callable objects......Page 50 Callable instances and the __call__() method......Page 51 Classes are Callable......Page 55 Leveraging callable classes......Page 56 Lambdas......Page 58 Detecting Callable Objects......Page 60 Extended Formal Parameter Syntax......Page 62 Extended Call Syntax......Page 70 Transposing Tables......Page 72 Summary......Page 76 Local functions......Page 78 Closures and nested scopes......Page 82 Function decorators......Page 90 Validating arguments......Page 103 Summary......Page 105 Class attributes......Page 107 Static methods......Page 112 Class methods......Page 114 Named constructors......Page 115 Overriding static- and class-methods......Page 118 Properties......Page 124 Overriding properies......Page 134 The template method pattern......Page 142 Summary......Page 145 Two string representations......Page 146 Strings for developers with repr()......Page 147 Strings for clients with str()......Page 148 When are the representation used?......Page 149 Precise control with format()......Page 151 Leveraging reprlib for large strings......Page 154 The ascii(), ord() and chr() built-in functions......Page 155 Case study: String representations of tabular data......Page 157 Summary......Page 159 Python's basic numeric types......Page 162 The limits of floats......Page 164 The decimal module......Page 166 The fractions module......Page 176 Complex Numbers......Page 178 Built-in functions relating to numbers......Page 184 Dates and times with the datetime module......Page 188 Case study: Rational numbers and computational geometry......Page 201 Summary......Page 231 Review of comprehensions......Page 233 Multi-input comprehensions......Page 234 map()......Page 239 filter()......Page 246 functools.reduce()......Page 248 Combining functional concepts: map-reduce......Page 251 The iteration protocols......Page 253 Case study: an iterable and iterator for streamed sensor data......Page 258 Summary......Page 260 Single inheritance......Page 263 Type inspection......Page 268 Multiple inheritance......Page 272 MRO: Method Resolution Order......Page 275 super()......Page 279 object......Page 287 Summary......Page 289 Collection protocols......Page 293 Test first......Page 294 The initializer......Page 295 The container protocol......Page 297 The sized protocol......Page 299 The iterable protocol......Page 302 The sequence protocol......Page 304 The set protocol......Page 326 Summary......Page 333 Exception dangers......Page 335 Exceptions hierarchies......Page 339 Exception payloads......Page 343 User-defined exceptions......Page 347 Exception chaining......Page 350 Tracebacks......Page 355 Assertions......Page 356 Preconditions, postconditions and assertions......Page 361 Summary......Page 370 What is a context manager?......Page 372 The context manager protocol......Page 374 contextlib.contextmanager......Page 384 Multiple context-managers in a with-statement......Page 388 Context managers for transactions......Page 393 Summary......Page 396 Introspecting types......Page 399 Introspecting objects......Page 401 Introspecting scopes......Page 405 The inspect module......Page 408 An object introspection tool......Page 413 Summary......Page 424 Afterword: Levelling Up......Page 426 Appendix A - Python implementation of ISO6346......Page 428
Similar books
The Python Apprentice
2017 · PDF
The Python Apprentice
2018 · EPUB
The Python Master (75% Complete)
2019 · PDF
The Python Master
2017 · EPUB
The Python Apprentice: A Practical and Thorough Introduction to the Python Programming Language
2017 · AZW3
The Python Apprentice: A Practical and Thorough Introduction to the Python Programming Language
2017 · PDF
The Python Apprentice
2017 · EPUB
The Python Apprentice
2016 · EPUB