This is a small how-to collection of basic Python code snippets. The code follows the lecture series by CSC course "Python programming" (fall 2015) by S. Lebedev (https://compscicenter.ru/courses/python/2015-autumn/classes/)
Content:
Lecture 2.
- Minimum function and fabric pattern
- Local, nonlocal and global objects
- Unpacking
- Functional aspects
Lecture 3. Decorators and functools
- Decorator examples
- Decorator with positional and kw-only arguments
- Functools module: lru_cache, single_dispatch
Lecture 5. Collections
- Tuples and Namedtuples
- Lists and deque
- Dicts, DefaultDicts, OrderedDicts
- Counters
Lecture 6. Classes (Part 1)
- Useful class decorators (singleton, deprecated)
- Mixin classes
- Magic methods
Lecture 7. Exceptions and Context managers
- Exceptions basic: try / except / else / finally
- Context Managers
- contextlib
Lecture 8. Iterators, generators and contextlibs
- Iterators, binary tree
- Generators: yield, send, throw, yield from, return
- Generators as iterators, coroutines, compact context managers
- itertools
Lecture 10. Classes (Part 2)
- Descriptors: get, set, delete
- Data and non-data descriptors, cached_property
- property, staticmethod and classmethod
- Metaclasses, new
- ABC and abstractmethod, collections.abc