How to Convert a Unicode String to a Dictionary in Python?

Problem Formulation Given a Unicode string representation of a dictionary. How to convert it to a dictionary? Input: u”{‘a’: 1, ‘b’: 2, ‘c’: 3}” Output: {‘a’: 1, ‘b’: 2, ‘c’: 3} Note: The u’string’ representation represents a Unicode string that was introduced in Python 3. This is redundant as all strings in Python 3 are … Read more

How to Log a Python Error with Debug Information?

[toc] Generally, logging is an extremely valuable tool in a software developer’s toolbox. Logging helps to assist you with the flow of a program and find situations that you probably would not have considered while coding. By logging useful data and information, you can troubleshoot the errors effectively as well as utilize the information to … Read more

Python List of Dunder Methods

When searching for a list of dunder methods, I only found a couple of resources all over the web—each covering only a fraction of dunder methods. So, here’s my collection of 127 dunder methods (also called “magic methods”) from those sources, sorted alphabetically: __abs__ __add__ __aenter__ __aexit__ __aiter__ __and__ __anext__ __await__ __bool__ __bytes__ __call__ __ceil__ … Read more

Python Version Backward Compatibility

The Python language does not generally provide backward compatibility. The ability to break inefficiencies and fix wrong design choices are major reasons why Python has remained lean and efficient over the last decades. However, the PEP 387 standard discusses that incompatibility issues should be well thought out. Here’s the basic policy when backward incompatibilities may … Read more

Pytest – A Complete Overview

Pytest is a popular test framework in Python. It helps to automate the test execution process and run unit tests as frequently as possible with minimal effort.  Everyone who has at least some experience with computer programming would intuitively know that testing is critical when building a software application. But beginners often find it difficult … Read more

bootstrap_plot() – Pandas Plotting Module

A bootstrap plot is a graphical representation of uncertainty in a characteristic chosen from within a population. While we can usually calculate data confidence levels mathematically, gaining access to the desired characteristics from some populations is impossible or impracticable. In this case, bootstrap sampling and the bootstrap plot come to our aid. This article will … Read more

Python Version AWS Lambda

The following table provides an overview of the Python versions supported by AWS SDK for Python: Name Operating system Python 3.9 Amazon Linux 2 Python 3.8 Amazon Linux 2 Python 3.7 Amazon Linux Python 3.6 Amazon Linux Python 2.7 Amazon Linux Boto3 is the Software Development Kit (SDK) for Python from Amazon Web Services (AWS). … Read more

The Complete Python Library Guide

This article is about a topic that is far more important and even more fundamental than any specific Python tutorial: Libraries. What Are the Top 10 Python Libraries? The following list reflects the most important Python libraries based on my experience: Pandas. “Excel for coders”. NumPy. Fundamental to many libraries in the data science and … Read more

How to Install Jupyter Notebook on PyCharm

1. Create a new Python project and install the jupyter package using the command pip install jupyter in the “Terminal” view. 2. Open or create a Jupyter notebook that is a file with the suffix .ipynb. 3. Add cells and execute them directly in PyCharm.

How to Check the Python Version at Runtime?

Method 1: sys.version To check your version at runtime in your code, import the sys module and print the sys.version attribute to your Python shell: Method 2: sys.version_info If you need an easy-to-process output for the major, minor, and micro versions, use the sys.version_info attribute. For example, Python version 3.9.5 has major version 3, minor … Read more