[ERROR FIXED] “Attempted relative import in non-package” even with __init__.py

[toc] Understanding the Error Problem Formulation: How to fix or deal with the following error – ” Attempted relative import in non-package”? Let’s say you have been working on your new project, and now you have decided to organize your project files properly. Hence, you move certain functions to another file to make your code … Read more

Python __aexit__() Magic Method

object.__aexit__(self, exc_type, exc_val, exc_tb) 💡 Summary: Python’s __aexit__() magic method is semantically similar to __exit__() but is used for asynchronous and parallel programming. Python calls the __aexit__() magic method when leaving an async with block whereas the __aenter__() method is called when entering it. An object that implements both __aenter__() and __aexit__() methods is called … Read more

Python __aenter__() Magic Method

object.__aenter__(self) 💡 Summary: Python’s __aenter__() magic method is semantically identical to __enter__() but is used for asynchronous and parallel programming. Python calls the __aenter__() magic method when starting an async with block whereas the __aexit__() method is called when leaving it. An object that implements both __aenter__() and __aexit__() methods is called an asynchronous context … Read more

How to Deploy a Smart Contract to Polygon in Brownie

This article will look at deploying a smart contract to Polygon using Brownie.  What is Polygon? Polygon is “a protocol and a framework for building and connecting Ethereum-compatible blockchain networks” (https://polygon.technology/). It started as Matic Network in 2017 to solve Ethereum’s scalability and user experience issues by using an ​off/side chain scaling solution. In 2021, … Read more

¿Cómo instalar una biblioteca en PyCharm?

Planteamiento del problema: Dado un proyecto de PyCharm. ¿Cómo instalar una biblioteca en tu proyecto dentro de un entorno virtual o de forma global? Solución que siempre funciona: Abre File > Settings > Project en el menú de PyCharm. Selecciona el proyecto actual. Haz clic en la pestaña Python Interpreter dentro de la pestaña del … Read more

Python __exit__() Magic Method

object.__exit__(self, exc_type, exc_value, traceback) 💡 Summary: Python calls the __exit__() magic method when ending a with block whereas the __enter__() method is called at the start. An object that implements both __exit__() and __enter__() is called a context manager. By defining those methods, you can create your own context manager. We define a custom class … Read more

Python __enter__() Magic Method

object.__enter__(self) 💡 Summary: Python calls the __enter__() magic method when starting a with block whereas the __exit__() method is called at the end. An object that implements both __enter__() and __exit__() methods is called a context manager. By defining those methods, you can create your own context manager. We define a custom class MySecretConnection. This … Read more

Python __format__() Magic Method

Syntax object.__format__(self, spec) The Python __format__() method implements the built-in format() function as well as the string.format() method. So, when you call format(x, spec) or string.format(spec), Python attempts to call x.__format__(spec). The return value is a string. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list … Read more

Python __set_name__() Magic Method

Python’s magic method obj.__set_name__(self, owner, name) method is created on an attribute obj when the class owner holding the attribute is created. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder methods with explanation, check out our dunder cheat sheet article on this … Read more

­­Handling Missing Data in Pandas: backfill(), bfill(), fillna(), dropna(), interpolate()

The Pandas DataFrame/Series has several methods to handle Missing Data. When applied to a DataFrame/Series, these methods evaluate and modify the missing elements. Preparation Before any data manipulation can occur, two (2) new libraries will require installation. The Pandas library enables access to/from a DataFrame. The NumPy library supports multi-dimensional arrays and matrices in addition … Read more