Logo Anna-Lena Popkes
  • Home
  • About
  • Skills
  • Experiences
  • Education
  • More
    Projects Talks & Podcasts Recent Posts
  • Posts
  • Dark Theme
    Light Theme Dark Theme System Theme
Logo Inverted Logo
  • Posts
  • Personal news
  • My path to machine learning
  • Books
    • Personal reading List
    • Deep work
  • Machine Learning
    • Bayesian linear regression
    • KL Divergence
    • Principal component analysis (PCA)
    • Support vector machines
    • Variational Inference
  • Python
    • Coding with kids
    • Mocking
    • Packaging tools
    • Magical Universe
      • Start
      • The Tales of Castle Kilmere
      • Object-oriented programming
      • Types of methods
      • Type annotations
      • To-string conversion
      • Decorators
      • Properties
      • Underscore patterns
      • Extending the universe
      • Duck Typing
      • Namedtuples
      • Abstract Base Classes
      • Data classes
      • Immutable data classes
      • Decorators in classes
      • if __name__ == "__main__"
      • Context managers
      • Testing with pytest
      • Iterators
      • Multisets
      • Extending the universe II
      • Exception classes
      • functools.wraps
      • Defaultdict
      • Config files
      • Wrap up
  • Software Engineering
    • Intro to containers
    • Intro to Docker
    • Intro to virtual machines
Hero Image
Decorators within classes

Topics: Decorators within a class Updated 2020-10-05 After having talked about decorators already on day 5 and day 6 I would like to revisit the topic to discuss how decorators can be used within classes. Let’s put ourselves in the position of a Castle Kilmere member during the time the school is in war with Master Odon and his Dark Army. So these are dark, scary times. People at Castle Kilmere are constantly scared that something might happen to them, their family or their friends.

Saturday, August 11, 2018 Read
Hero Image
Immutable data classes

Topics: Immutable data classes Updated 2020-10-05 We have talked a lot about data classes in the last post. There is one further characteristic of data classes that I would like to study - immutability. We can make a dataclass immutable such that it fulfills the same purpose as typing.NamedTuple. To make a dataclass immutable we have to set frozen=True when creating the class. Let’s see how we can change our DarkArmyMember class from typing.

Friday, August 10, 2018 Read
Hero Image
Data classes

Topics: Data classes Updated 2020-10-05 Data classes are a feature that is new in Python 3.7. And taking a look at them is definitely worth it! Data classes According to the PEP on data classes, they are basically “mutable namedtuples with defaults”. We already looked at namedtuples on day 10 and 11. Namedtuples allow us to create an immutable class that primarily stores values (i.e. attributes). We used namedtuples for our DarkArmyMember class (because once you become a member of the dark army there is no way back.

Wednesday, August 8, 2018 Read
Hero Image
Abstract Base Classes

Topics: Abstract Base Classes, ABC’s Updated 2020-10-05 The last days I have been working on a lot of new classes and methods. Since they all belong to the same big concept, I decided to create one big post on the whole topic instead of several small ones. So let’s get right into it! Abtract Base Classes Up to now, our Magical Universe has a parent class (CastleKilmereMember) and several child classes (Pupil, Professor, etc.

Saturday, August 4, 2018 Read
Hero Image
Namedtuples

Topics: Immutable classes, namedtuples Updated 2020-10-04 Tuples Before looking at namedtuples, we should review what a tuple is. In Python, a tuple is a simple data structure that can be used for grouping arbitrary objects. Important to know is that tuples are immutable. That means that once a tuple has been created, it can not be changed anymore. We already used tuples in our Magical Universe. For example, we defined the pet attribute of the Pupil class to be a tuple:

Wednesday, August 1, 2018 Read
Hero Image
Duck typing, EAFP principle

Topics: Duck typing, EAFP principle Updated 2020-10-04 Duck typing Today we are going to look at some fundamental philosophies of programming: duck typing, EAFP and its opposite LBYL. Some of you may have heard of these principles already. However, because they are so fundamental we want to make sure that we apply them to our magical universe correctly. So what is duck typing? The most common saying regarding duck typing is “If it walks like a duck, and it quacks like a duck, then it must be a duck.

Tuesday, July 31, 2018 Read
Hero Image
Extending the Magical Universe

Topics: Adding new classes and methods to the Magical Universe Today I used some of the concepts introduced during the last days to extend my Magical Universe. Specifically: I added a classmethod for creating the ghost ’the mocking knight' I added a ‘friends’ attribute to the Pupil class I added methods for adding and listing all current friends of a Pupil I implemented a new Charm class that allows to create charms I added two classmethods for creating popular charms

Monday, July 30, 2018 Read
Hero Image
Underscore patterns for variable naming

Topics: underscore patterns for variable naming, _variable, __variable, __variable__, _ Updated 2020-10-04 Underscore patterns for variable naming Today we are going to look at a very important concept in Python: the usage of underscores when naming variables! In Python we have five different naming conventions that involve underscores. A variable with a single leading underscore like _elms This is a naming convention followed by most Python code A name prefixed with an underscore should be treated as a non-public part of the API and it might be changed without notice This holds independent of whether it is a function, a method or a data member A variable with (at least) two leading underscores and at most one trailing underscore like __my_private_variable

Sunday, July 29, 2018 Read
Hero Image
Properties, setter and getter methods

Topics: properties, @property and property(), setters, getters Updated 2020-10-04 Today, I digged a little deeper into the @property decorator, how it is related to the property() function and how its getter and setter methods work. These two links (link1, link2) were really helpful. Of course, there is also the official Python docs on the property() function. The @property decorator Yesterday we looked at decorators. The @property decorator allows us to create a read-only property.

Saturday, July 28, 2018 Read
Hero Image
Decorators

Topics: decorators Updated 2020-10-04 Today, we are going to look at decorators. Python’s decorators are an advanced concept so don’t worry if you don’t immediately understand how they work. The more you will use and read about them, the clearer the concept will become. I won’t go into too much detail here, so if you want to know more about decorators, take a look at Dan Bader’s website or the PEP on decorators.

Friday, July 27, 2018 Read
Hero Image
To-string conversion

Topics: to-string conversion, __repr__, __str__ Updated: 2020-10-04 To-string conversion Today we are going to look at the two methods that control how an object is converted into a string object. When we just print an object, we won’t get a useful representation. For example, when trying to print the bromley instance: bromley = CastleKilmereMember(name='Bromley Huckabee', birthyear=1959, sex='male') print(bromley) We get this output: <__main__.CastleKilmereMember object at 0x7f81853bfc50>. It contains the name of the class an the ID of the object (its memory address).

Thursday, July 26, 2018 Read
Hero Image
Type annotations

Topics: Type annotations Updated 2020-10-04 Type annotations Type annotations are a very cool feature that came out with Python 3.5. They allow us to add arbitrary metadata to function arguments and the return value of a function. Why this is useful? First of all, it allows us to document of what type our function parameters are. Furthermore, they can be used for things like type checking. For more use cases, look here.

Wednesday, July 25, 2018 Read
  • ««
  • «
  • 1
  • 2
  • 3
  • 4
  • »
  • »»
Navigation
  • About
  • Skills
  • Experiences
  • Education
  • Projects
  • Talks & Podcasts
  • Recent Posts
Contact me:
  • popkes@gmx.net
  • zotroneneis

Toha Theme Logo Toha
© 2020-2021 Copyright.
Powered by Hugo Logo