Follow me
-
Recent Posts
calendar
November 2024 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Recent Comments
- Stan on python argparse issues with the help argument (TypeError: %o format: a number is required, not dict)
- Cormac on Pandas : how to compare dataframe with None
- LP on AWK: the substr command to select a substring
- jrab on python argparse issues with the help argument (TypeError: %o format: a number is required, not dict)
- How to disable SSL verification for urlretrieve? – Peter's blog on python: certificate verified failed
Archives
Categories
Meta
Category Archives: Python
Nice vscode extensions
Whether you are a new developer, or an expert developer, you should really consider using vscode https://code.visualstudio.com I have to admit I have been using VIM for years and I believe will always use it. I tried some great tools … Continue reading
How to use subprocess with PIPEs
In Python, the subprocess module allows you to execute linux/unix commands directly from Python. The official Python documentation is very useful would you need to go further. Yet it may be a bit scary for newbies. Syntax may also change … Continue reading
how to set the logging in DEBUG mode when using the python requests package
By default when using the excellent requests package, there is not much on the screen to figure out was goes wrong with a specific URL requests. In general, you do not need it but from time to time it is … Continue reading
How to get pypi statistics about package download
A while ago, I designed pypiview, a Python package used to fetch the number of downloads for a package hosted on pypi website. It used to work decently but according to pypi itself the values stored are not reliable and … Continue reading
How to sort a dictionary by values in Python
By definition, dictionary are not sorted (to speed up access). Let us consider the following dictionary, which stores the age of several persons as values: d = {"Pierre": 42, "Anne": 33, "Zoe": 24}d = {"Pierre": 42, "Anne": 33, "Zoe": 24} … Continue reading
Python: how to copy a list
To explain how to create a copy of a list, let us first create a list. We will use a simple list of 4 items: list1 = [1, 2, "a", "b"]list1 = [1, 2, "a", "b"] Why do we want … Continue reading
Python: ternary operator
In C language (and many other languages), there is a compact ternary conditional operator that is a compact if-else conditional construct. For instance, in C, a traditional if-else construct looks like: if (a > b) { result = x; } … Continue reading
Posted in Python
Leave a comment
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
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
pytest-cov collects no data on Travis
I recently switched from nosetests to pytest and pytest-cov for one of my Python project (http://easydev-python.readthedocs.io). Locally, everything seemed to work fine and once on Travis, all tests passed as expected. Yet, before the coverage report, I noticed this warning: … Continue reading