Techno Blender
Digitally Yours.
Browsing Tag

Marcin

rounder: Rounding Numbers in Complex Python Objects | by Marcin Kozak | Oct, 2022

The rounder package enables you to round all numbers in any object, with just one commandrounder: Rounding numbers in Python has never been easier. Photo by Mika Baumeister on UnsplashRounding numbers seldom causes problems. In the standard library, we have function round(), math.ceil() and math.floor(), thanks to which we can use three standard types of rounding. This should suffice, shouldn’t it?Not always, actually. Imagine you have the following object that you want to round to two decimal digits:Note: In this…

Parallelization in Python: The Easy Way | by Marcin Kozak | Oct, 2022

Parallelization does not have to be difficultParallelization in Python does not have to be difficult. Photo by Abbas Tehrani on UnsplashMany beginners and intermediate Python developers are afraid of parallelization. To them, parallel code means difficult code. Processes, threads, greenlets, coroutines… Instead of ending up with performant code, work on parallelizing code often ends up in headaches and frustration.In this article, I want to show that this does not have to be the case. In simple scenarios, code can be…

Importing Objects from a Python Module Can Be Risky | by Marcin Kozak | Oct, 2022

Do you know if you work with original objects after importing them? Maybe with their copies? Maybe some are original and others are copies?Which horse is original and which is a copy? It’s so difficult to say! Source: Image by author.Whether you should import a module (import module) or import objects from a module (from module import obj1, obj2) is not a new issue. In this article, I am not going to reinvent the wheel. We know that importing a module has more advantages, but in some situations direct importing objects…

Comparing floating-point numbers with easycheck | by Marcin Kozak | Oct, 2022

easycheck can help you compare floats in assertion-like situationsComparing floating-point numbers. Image by author.Comparing floating-point numbers in Python is simpler than you may think. This is thanks to the math module, but not only. This topic has been recently very nicely described by David Amos in his Towards Data Science article, so if you’re interested in the basics, please read it first.In this article, I will show you how to compare floating-point numbers in assertion-like situations. One should not use the…

Should we use custom exceptions in Python? | by Marcin Kozak | Oct, 2022

Python has so many built-in exceptions that we rarely need to create and use custom ones. Or do we?Custom exceptions: Own your own error. Photo by Brett Jordan on UnsplashShould we use custom exceptions or built-in ones? That’s a very good question, actually. Some say,Avoid custom exceptions at all costs. There are so many built-in exceptions that you seldom need a custom one, if ever.Others say,Use custom exceptions in your projects. Leave built-in exceptions to typical situations in which they are raised, and raise…

Benchmarking Python code with timeit | by Marcin Kozak | Oct, 2022

The most popular tool for time benchmarking of Python code, the built-in timeit module offers more than most Pythonistas knowThe timeit module is Python’s stopwatch. Photo by Tsvetoslav Hristov on UnsplashBenchmarking is seldom done for the fun of it, even if it is a lot of fun indeed. In addition to this fun, it can help you in:understanding Python behavior; you can learn what is quicker and what is slower, which in turn can help you understand the language;optimizing your code.If you think you spend too much time…

Does Python still need the map() function? | by Marcin Kozak | Oct, 2022

Having various alternatives, Python’s map() seems to be redundant. So, does Python need it at all?Does Python need the map() function? Photo by Muhammad Haikal Sjukri on UnsplashDon’t worry, this will not be the millionth article on how to use map() in Python. I am not going to tell you that it’s better or worse than a list comprehension or a for loop. I am not going to benchmark it against its corresponding generator or list comprehension. I am not going to claim that using map() will make you look like an advanced…

The 2022 Ig Nobel Winners Are Here: Constipated Scorpions and More

The truth can finally be unearthed.Image: Shutterstock (Shutterstock)This year’s Ig Nobel winners are here, and they’re just as eye-catching and baffling as usual. Among the selections are a study showing that love at first sight may be detectable through synchronized heartbeats, an answer to why legal documents are so incomprehensible, and the discovery of the most effective way to open a door.Running since 1991, the Ig Nobels are the brainchild of the Annals of Improbable Research magazine and are co-sponsored by the