
Plotting a circle with matplotlib library in python is an interesting task. If you google it, you will find quite good answers, but anyway, I am here because I want to summarize my point of view. Pretty much, the idea…
Python code examples
Reading from a pdf is actually quite an easy task with Python. If the PDF is of course “readable”, e.g. made from a word processor. The first thing to do is to install Tika and Java:
1 2 3 |
pip install tika <em>conda install</em> -c conda-forge <em>tika # as alternative</em> java --version #this one checks the installed java version in the command prompt |
Having this, the…
If you have ever dreamed that it will be possible to fill out an Excel cell with a picture, using Python, then you should probably reevaluate your dreams. Seriously, who dreams of something like that? Without further dreaming, the code…
Have you seen the error below?
1 2 3 4 5 6 |
Traceback (most recent call last): File "C:/Users/foo/PycharmProjects/pythonProject3/main.py", line 29, in <module> main() File "C:/Users/foo/PycharmProjects/pythonProject3/main.py", line 19, in main a['foo'] += 5 KeyError: 'foo' |
Of course you have. And you know, that it is because you have written something extremely unwise like this:
1 2 |
a = dict() a['foo'] += 5 |
Yeah. You cannot increment the value of a non-existent key. Unless… Unless you…
Intersection of dictionary (or of any two lists) is a list with elements, that are present in both other lists. Thus, if we have the following 3 dictionaries in Python:
1 2 3 |
dict_a = dict([('aa', 4139), ('bb', 4127), ('cc', 4098)]) dict_b = dict(aa=4139, bb=4127, ee=4098) dict_c = {'aa':12, 'bb':13, 'dd':23} |
Then, an intersection of their keys will contain only…
In the previous article for abstraction and inheritance I wrote some classes, showing the basics of these two programming concepts. In this one, I will write unit tests for one of the classes, written before. Software testing is an important…
Python – Docstring – Help and Comments
Docstrings in Python are actually quite simple – the are 3 times this """ and the code between opening and closing them can be formatted in any possible way. The reason I have decided to dedicate a whole article to…