Magical Universe

On July 23rd 2018 I started working on a new habit (for details see my blog post), namely coding for at least 15 minutes a day. The major goal of this new habit was (and still is) to continously improve my coding skills.

As part of the habit I’ve started creating a series of blog posts on important and awesome Python features, including object oriented programming, properties, function annotations, duck typing, etc.

Since I was bored by the usual tutorial examples, I looked for a topic that would make it fun to study and implement the concepts. And since I absolutely love Harry Potter, I started creating my own Magical Universe around the topics.

All code can be found in this GitHub repository. My blog features the corresponding blog posts.

Overview

DayTopicsBlog post with explanationsCode for the day
1Intro to object oriented programming, classes, inheritanceDay 1Code day 1
2Class methods, instance methods, static methods, using class methods as alternative constructorsDay 2Code day 2
3Function annotationsDay 3Code day 3
4To-string conversion, __repr__, __str__Day 4Code day 4
5DecoratorsDay 5No new code added
6Properties, @property and property(), setters, gettersDay 6Code day 6
7Underscore patterns for variable naming, _variable, __variable, __variable__, etc.Day 7No new code added
8New methods and classes added to the HP universeDay 8Code day 8
9Duck typing, EAFP principleDay 9Code day 9
10 & 11NamedtuplesDay 10 & 11Code day 10 & 11
12 - 15Abstract Base ClassesDay 12 to 15Code day 12 to 15
16 - 18Data ClassesDay 16 to 18Code day 16 to 18
19Immutable Data ClassesDay 19Code day 19
20Decorators within a classDay 20Code day 20
21The mysterious if __name__ == "__main__"Day 21No new code added
22 - 24Context managers and the with statementDay 22 to 24Code day 22 to 24
25 - 28Testing code with pytestDay 25 to 28Code day 25 to 28
29 - 31Iterators, iterables, iterationDay 29 to 31Code day 29 to 31
32Test code for Professor classNo blog post, see Day 25 to 28 for an introduction to testingCode day 32
33Test code for Ghost classNo blog post, see Day 25 to 28 for an introduction to testingCode day 33
34Counting objects with Collections.counterDay 34Day 34
35Test code for DarkArmyMember classNo blog post, see Day 25 to 28 for an introduction to testingCode day 35
36Test code for Potion classNo blog post, see Day 25 to 28 for an introduction to testingCode day 36
37Extension of Magical Universe with classmethods for Charm, Hex, Curse, etc.Day 37Code day 37
38 - 39Test code for Spell classNo blog post, see Day 25 to 28 for an introduction to testingCode day 38 to 39
40 - 42Test code for Pupil classNo blog post, see Day 25 to 28 for an introduction to testingCode day 40 to 42
43 - 45Custom exception classesDay 43 to 45Code day 43 to 45
46functools.wraps - Avoiding losing metdata when applying decoratorsDay 46Code day 46
47 - 48collections.defaultdictDay 47 to 48Code day 47 to 48
49 - 50Working with config filesDay 49 to 50Code day 49 to 50
51Wrap upDay 51No new code added