Learning Python – Advanced Level

You have gone through the first two parts of the series – the beginner level and the intermediate level.

The topics that are given in this post are advanced level Python programming.

The following section will give you the links to the posts where you can find the best explanations for all that you will need to learn from this. 

1. Python Comprehensions

Comprehensions are constructs that allow sequences to be built from other sequences. Python 2.0 introduced list comprehensions and Python 3.0 comes with dictionary and set comprehensions.

Compact Reference:

Python: List Comprehensions

Python Course – Comprehensions

Other References:

Python Tutorial Docs – Comprehensions

Python For Beginners – Comprehensions

2. Iterators and Generators

According to Wikipedia, an iterator is an object which allows a programmer to traverse through all the elements of a collection, regardless of its specific implementation. In Python programming language, an iterator is an object which implements the iterator protocol.

Compact Reference:

Iterators and Generators

Iterables vs Iterators vs Generators

Difference between Iterators and Generators

Other References:

PyM Book – Learn Python – Iterators and Generators

Iterators and Generators

Iterables, Iterators and Generators – Part 1

Iterables, Iterators and Generators – Part 2

3. Python Decorators

Decorators allow you to make simple modifications to callable objects like functions, methods or classes. In the context of design patterns, decorators dynamically alter the functionality of a function, method or class without having to directly use subclasses. This is ideal when you need to extend the functionality of functions that you don’t want to modify. We can implement the decorator pattern anywhere, but Python facilitates the implementation by providing much more expressive features and syntax for that.

Compact Reference:

Learn Python – Decorators

Understanding Python Decorators in 12 easy steps

A guide to Python’s Function Decorators

Other Reference:

Python Docs – Generators

4. Python Context Managers

A basic issue in programming is resource management a resource is anything in limited supply, notably file handles, network sockets, locks, etc., and a key problem is making sure these are released after they are acquired. If they are not released, you have a resource leak, and the system may slow down or crash. More generally, you may want cleanup actions to always be done, other than simply releasing resources.

Python provides special syntax for this in the with statement, which automatically manages resources encapsulated within context manager types, or more generally performs startup and cleanup actions around a block of code. You should always use a with statement for resource management. There are many built-in context manager types, including the basic example of File, and it is easy to write your own.

Context managers are a way of allocating and releasing some sort of resource exactly where you need it.

Compact Reference:

Introduction to Context Managers in Python

Implementing a Context Manager

Context Managers in Python

Other Reference:

Understanding Context Managers – Stack Overflow

Context Managers in Python

Context Managers – Python

5. Python Descriptors

Python descriptors were introduced in Python 2.2, along with the new style classes, yet they remain widely unused. Python descriptors are a way to create managed attributes. Among their many advantages, managed attributes are used to protect an attribute from changes or to automatically update the values of a dependent attribute. Descriptors increase an understanding of Python and improve coding skills.

Compact Reference:

Python Descriptors Demystified

Python Descriptor How To – Python Docs

Introduction to Python Descriptors

Other Reference:

Explaining Descriptors

Python Descriptors-Inform IT

Python Descriptors – Properties

Python descriptors – Part 1

6. Metaclasses

In Python, classes are themselves objects. Just as other objects are instances of a particular class, classes themselves are instances of a metaclass. The Pep 3115 defines the changes to python 3 metaclasses. In Python-3 you have a method _prepare_ that is called in the metaclass to create a dictionary or other class to store the class members. Then there is the _new_ method that is called to create new instances of that class.

Compact Reference:

A primer on Python Metaclasses

Python Programming Metaclasses Wikibooks

Python Metaclasses

Other Reference:

Python Metaclasses By Example

Advanced use of Python Metaclasses and Decorators

Python Metaprogramming

All about the metaclasses in Python

7. Python Conventions:

The following resources will give you the Python coding conventions. Coding, naming conventions, and all that you will need to write a clean Python code.

Compact Reference:

Python Code Style

Pep-8 Style Guide for Python

Code Like A Pythonista

Other Reference:

Python Style Guide

Python Naming Conventions

A beginner’s guide to Code Standards in Python

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>