Daily Archives: December 26, 2017

Difference between __repr__ and __str__ in Python

When implementing a class in Python, you usually implement the __repr__ and __str__ methods. __str__ should print a readable message __repr__ should print a message that is unambigous (e.g. name of an identifier, class name, etc). You can see __str__ … Continue reading

Posted in Python | Tagged , | 3 Comments

python: how to merge two dictionaries

Let us suppose two dictionaries storing ages of different individuals: list1 = {"Pierre": 28, "Jeanne": 27} list2 = {"Marc": 32, "Helene": 34}list1 = {"Pierre": 28, "Jeanne": 27} list2 = {"Marc": 32, "Helene": 34} If you do mind losing the contents … Continue reading

Posted in Python | Tagged | Leave a comment

Search for a pattern in a set of files using find and grep commands

A common task for developers is to search for a pattern amongst a bunch of files that are in different directories. For instance, you are looking for the pattern “import sys” within a set of Python files. Those files are … Continue reading

Posted in Linux | Tagged , | Leave a comment