Python Advanced (7.9.2020 - 10.9.2020)

This is a training for a team which is already experienced in Python programming. There were some special requirements for the training, such as to loose a couple of words about AI/machinelearning and other topics, as well as a fuzzy “bring us advanced stuff”.

The training was accompanied by a lot of improvised live hacking.

Preparation

Workspace Setup

Github for Exercises

Please create Github accounts and send them to training@faschingbauer.co.at. We will do exercises via a private repository on Github. (See the privacy statement.)

Agenda

Advanced Core Python Topics

Python is easy; one can solve nontrivial problems in only a few lines of code, in no time. This does not mean that you have to fully understand the language - which is good because this is what makes the language easy.

On the other hand, there’s always a line to cross where you wish you knew more. Here the more advanced core Python topics that shall be covered.

Special Topics

Log

Following is a recap of what has happened. File names are relative to the root of the Github repository we were working from.

Day 1

Rushed through basics,

Put a strong focus on Python features,

Day 2

  • Livehacking: Iteration, Comprehensions, and Generators, covering

    • List comprehensions

    • The range function

    • Writing generators using yield

    • Generator expressions

  • Livehacking OO

  • Livehacking design patterns

    • joerg-livehacking/composite.py. Using the thermometer hierarchy, a “composite” thermometer was created. That thermometer uses (has) a set of concrete thermometers to calculate the average room temperature.

    • joerg-livehacking/adapter.py. Fictional scenario …

      • The Unser thermometer framework contains a number of thermometer implementations which all support the get_temperature_celsius() method.

      • A collaboration with a competitor is launched. That competitor has a similar set of thermometer implementations. The difference between Eana and Unser is that Eana thermometers do not support get_temperature_celsius(), but rather only get_temperature_fahrenheit().

      • We employ the adapter pattern and create one special thermometer in the Unser hierarchy

        class EanaAdapter(UnserThermometer):
            ...
        

Day 3

  • Revisit abstract base classes

  • Visitor pattern. Not every pattern in the “Gang of Four” book should be considered a real pattern. For example, the Visitor pattern turn into an idiom for languages that don’t support generators.

    • joerg-livehacking/visitor.py. Classic OO implementation of the visitor pattern as a DFS traversal. Together with callbacks and all convolutions. Took sideways like,

      • show how __call__ makes a class callable.

      • show how __str__ and __repr__ work together in print()

    • joerg-livehacking/visitor-generator.py. “I don’t want to implement a visitor!”, poor user says. “I only want to iterate over the tree in DFS order!”

      Implement DFS iteration using yield from which delegates iteration into recursion.

  • TDD and Unit Testing theory; using excerpts from the Design Patterns deck of slides. Explain terminology; fixtures and such.

  • Start hacking on project. Agreed upon myself doing live hacking. Doing TDD.

    • Project/sensor/sensordata.py, and Project/tests/sensordata_tests.py. Prepare TDD; explain suites, cases, fixture, assertions.

    • While writing data classes (holding only attributes and no functionality), explain namedtuple. Use that to implement sensor.sensordata.HistoryData.

    • Slowly fix things, in a test driven way. Discuss, team giving input, all really fine.

Day 4

After Work Party

From my point of view, the training went really fine. Not everyone is equally satisfied with the outcome (we didn’t get to the AI topics, for example), but I have the impression that I brought it over.

As a gift to myself, I had reserved Thursday night at Gmundner Hütte. After the training I went back to Hoisn Wirt (which is where I stayed during the training - really fine), changed clothes, and started to climb the Traunstein via Zierlersteig.

See here for the description and pictures from this extraordinary hike.

Graph

cluster_python Python Programming: From Absolute Beginner to Advanced Productivity cluster_python_basics Python: The Language Fundamentals cluster_python_swdev Python: Project/Package Management cluster_python_misc Python: Miscellaneous Topics cluster_python_misc_ai Machine Learning, Artificial Intelligence cluster_python_advanced Python: More Language Features cluster_python_advanced_oo Object Oriented Programming python_basics_python_0193_while while Loops python_basics_python_0170_if The if Statement python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0160_boolean Boolean python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_installation Python Installation python_basics_python_0150_datatypes_overview_compound Compound Datatypes python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0150_datatypes_overview_compound->python_basics_python_0150_datatypes_overview python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0120_helloworld Hello World python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0270_functions Functions python_basics_python_0270_functions->python_basics_python_0150_datatypes_overview python_basics_python_0140_variables Variables python_basics_python_0270_functions->python_basics_python_0140_variables python_basics_python_0225_range The range Function python_basics_python_0220_for for Loops python_basics_python_0225_range->python_basics_python_0220_for python_basics_python_0200_sequential_types Sequential Datatypes python_basics_python_0225_range->python_basics_python_0200_sequential_types python_basics_python_0220_for->python_basics_python_0193_while python_basics_python_0220_for->python_basics_python_0200_sequential_types python_basics_python_0320_strings_methods Miscellaneous String Methods python_basics_python_0300_strings More About Strings python_basics_python_0320_strings_methods->python_basics_python_0300_strings python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0200_sequential_types->python_basics_python_0150_datatypes_overview_compound python_basics_python_0250_refs_flat_deep_copy References, (Im)mutability python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview_compound python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0140_variables python_basics_python_0110_blahblah Blahblah python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0300_strings->python_basics_python_0150_datatypes_overview python_basics_python_0300_strings->python_basics_python_0200_sequential_types python_basics_python_0300_strings->python_basics_python_0250_refs_flat_deep_copy python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_swdev_venv Virtual Environments python_swdev_pip Python Package Index python_swdev_venv->python_swdev_pip python_misc_import The import Statement (incomplete) python_swdev_venv->python_misc_import python_swdev_pip->python_misc_import python_misc_context_manager Context Managers (the with Statement) (incomplete) python_misc_context_manager->python_basics_python_0140_variables python_advanced_python_1010_generators_yield Iteration, Generators, And yield python_misc_context_manager->python_advanced_python_1010_generators_yield python_advanced_decorators Decorators python_misc_context_manager->python_advanced_decorators python_advanced_exceptions Exception Handling python_misc_context_manager->python_advanced_exceptions python_misc_encoding Encoding python_misc_encoding->python_basics_python_0320_strings_methods python_misc_encoding->python_basics_python_0150_datatypes_overview python_advanced_modules Modules and Packages python_misc_import->python_advanced_modules python_misc_ai_machine_learning_intro Machine Learning: Concepts and Terminology python_misc_ai_k_means K-Means python_misc_ai_k_means->python_swdev_venv python_misc_ai_k_means->python_misc_ai_machine_learning_intro python_misc_ai_linear_regression Linear Regression python_misc_ai_k_means->python_misc_ai_linear_regression python_misc_ai_linear_regression->python_swdev_venv python_misc_ai_linear_regression->python_misc_ai_machine_learning_intro python_advanced_starargs Positional and Keyword Arguments python_advanced_starargs->python_basics_python_0270_functions python_advanced_python_1010_generators_yield->python_basics_python_0270_functions python_advanced_python_1010_generators_yield->python_basics_python_0225_range python_advanced_python_1010_generators_yield->python_basics_python_0220_for python_advanced_python_1010_generators_yield->python_basics_python_0200_sequential_types python_advanced_closures Closures python_advanced_closures->python_basics_python_0270_functions python_advanced_decorators->python_basics_python_0270_functions python_advanced_decorators->python_advanced_starargs python_advanced_decorators->python_advanced_closures python_advanced_exceptions->python_basics_python_0270_functions python_advanced_exceptions->python_basics_python_0140_variables python_advanced_oo_inheritance Inheritance python_advanced_exceptions->python_advanced_oo_inheritance python_advanced_oo_constructor Constructor python_advanced_oo_classes_and_dicts Classes And Dictionaries python_advanced_oo_constructor->python_advanced_oo_classes_and_dicts python_advanced_oo_classes_and_dicts->python_basics_python_0150_datatypes_overview_compound python_advanced_oo_inheritance->python_advanced_oo_constructor python_advanced_oo_inheritance->python_advanced_oo_classes_and_dicts python_advanced_oo_operator_overloading Operator Overloading python_advanced_oo_operator_overloading->python_advanced_oo_classes_and_dicts