SitePoint
Blog
Forum
Library
Login
Join Premium
Toggle sidebar
The Python Journeyman
Toggle community discussions
Close
Content
Bookmarks
Preface
The Python Journeyman
Preface
Welcome Journeyman!
Prerequisites
Well begun is half done
1
Organizing Larger Programs
Packages
Implementing packages
Relative imports
__all__
Namespace packages
Executable directories
Executable packages
Recommended layout
Modules are singletons
Summary
Beyond Basic Functions
Review of Functions
Functions as callable objects
Callable instances and the __call__() method
Classes are Callable
Leveraging callable classes
Lambdas
Detecting Callable Objects
Extended Formal Parameter Syntax
Extended Call Syntax
Transposing Tables
Summary
Closures and Decorators
Local functions
Closures and nested scopes
Function decorators
Validating arguments
Summary
Properties and Class Methods
Class attributes
Static methods
Class methods
Named constructors
Overriding static- and class-methods
Properties
Overriding properties
The template method pattern
Summary
Strings and Representations
Two string representations
Strings for developers with repr()
Strings for clients with str()
When are the representation used?
Precise control with format()
Leveraging reprlib for large strings
The ascii() , ord() and chr() built-in functions
Case study: String representations of tabular data
Summary
Numeric and Scalar Types
Python’s basic numeric types
The limits of floats
The decimal module
The fractions module
Complex Numbers
Built-in functions relating to numbers
Dates and times with the datetime module
Case study: Rational numbers and computational geometry
Summary
Iterables and Iteration
Review of comprehensions
Multi-input comprehensions
Functional-style tools
map()
filter()
functools.reduce()
Combining functional concepts: map-reduce
The iteration protocols
Case study: an iterable and iterator for streamed sensor data
Summary
Inheritance and Subtype Polymorphism
Single inheritance
Type inspection
Multiple inheritance
MRO: Method Resolution Order
super()
object
Inheritance for Implementation Sharing
Summary
Implementing Collections with Protocols
Collection protocols
Test first
The initializer
The container protocol
The sized protocol
The iterable protocol
The sequence protocol
The set protocol
Summary
Errors and Exceptions in Depth
Exception dangers
Exceptions hierarchies
Exception payloads
User-defined exceptions
Exception chaining
Tracebacks
Assertions
Preconditions, postconditions and assertions
Summary
Defining Context Managers
What is a context manager?
The context manager protocol
contextlib.contextmanager
Multiple context-managers in a with-statement
Context managers for transactions
Summary
Introspection
Introspecting types
Introspecting objects
Introspecting scopes
The inspect module
An object introspection tool
Summary
Afterword: Levelling Up
Appendix A - Python implementation of ISO6346
Notes
Open text modal
Community Questions
Close