Month: September 2021

How to Fix UnicodeDecodeError when Reading CSV file in Pandas with Python?

Introduction In general, encoding means using a specific code for the letters, symbols, and numbers. Numerous encoding standards that are used for encoding a Unicode character. The most common ones are utf-8, utf-16, ISO-8859-1, latin, etc. For example, the character $ corresponds to U+0024 in utf-8 standard and the same corresponds to U+0024 in UTF-16 …

How to Fix UnicodeDecodeError when Reading CSV file in Pandas with Python? Read More »

What’s the Difference Between exit(0) and exit(1) in Python?

The function calls exit(0) and exit(1) are used to reveal the status of the termination of a Python program. The call exit(0) indicates successful execution of a program whereas exit(1) indicates some issue/error occurred while executing a program. What is the Exit Code? Letโ€™s have a look at some examples to get a clear picture …

What’s the Difference Between exit(0) and exit(1) in Python? Read More »

Why Does “pip search” Lead to an ERROR: XMLRPC request failed?

Today, when trying to get some information about specific pip packages, I wanted to use the pip search command in my local computer’s PowerShell. pip search Here’s the syntax: py -m pip search [options] <query> The semantics of pip search is to find PyPI packages that contain the <query> in their package name. Error Message …

Why Does “pip search” Lead to an ERROR: XMLRPC request failed? Read More »

dir() versus __dir__() – What’s the Difference?

Problem Formulation What’s the difference between the built-in dir() function and __dir__ dunder method in Python? Quick Answer Python’s built-in function dir(object) returns a list of the object’s attribute names and method names. The dir() function is a wrapper around the __dir__() method because it internally calls the object’s dunder method object.__dir__(). But the two …

dir() versus __dir__() – What’s the Difference? Read More »

How to Convert a String to a Dictionary in Python?

Problem Formulation Given a string representation of a dictionary. How to convert it to a dictionary? Input: ‘{“1”: “hi”, “2”: “alice”, “3”: “python”}’ Output: {‘a’: 1, ‘b’: 2, ‘c’: 3} Method 1: eval() The built-in eval() function takes a string argument, parses it as if it was a code expression, and evaluates the expression. If …

How to Convert a String to a Dictionary in Python? Read More »

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 …

How to Convert a Unicode String to a Dictionary in Python? Read More »