[Collection] All Finxter Articles and Tutorials

Manipulating Dates and Times in Python

In this article we will cover some basic features of the datetime module in Python. More specifically, we will see how to extract the current date and time and how to implement these features within a script in order to realize time-driven actions. Table of Contents Long Story ShortThe datetime ModuleGet the Current Date and

​Read More

Converting Integer to String in Python

Quick Fix: Python’s built-in str(x) method converts an integer object x to a string object by using the x.__str__() method. Table of Contents ❖ Introduction🖋️ Method 1: Using The str() Method🖋️ Method 2: Using The format() Function🖋️ Method 3: Using String Conversion ‘%s‘🖋️ Method 4: Using f-strings🖋️ Method 5: Using a Custom Method❖ ConclusionRelated Posts

​Read More

[Fixed] ImportError: No module named requests

Problem Formulation: How to fix ImportError: No module named requests in Python? You might be working on a web scraping project and want to import the requests library and check the status of the response. However, as soon as you try to execute your code, Python throws ImportError as shown below. Example: Output: ✨ The Requests Library Requests

​Read More

The Reduce Function in Python 3: Simply Explained

💡 The reduce() function from Python’s functools module aggregates an iterable to a single element. It repeatedly merges two iterable elements into a single one as defined in the function argument. By repeating this, only a single element will remain — the return value. Minimal Example Here’s the minimal example: The code performs the following steps:

​Read More

How to Run a Scrapy Spider from a Python Script

Scrapy is a framework for building web crawlers and includes an API that can be used directly from a python script.  The framework includes many components and options that manage the details of requesting pages from websites and collecting and storing the desired data.   The typical way to run scrapy is to use the

​Read More

How To Remove All Non-Alphabet Characters From A String?

💡 Summary: This blog explores the steps to remove all non-alphabet characters from a given string. The ‘re’ module in Python provides regular expression operations, to process text. One uses these operations to manipulate text in strings. The compile() method in conjunction with the sub() method can remove all non-alphabet characters from a given string. Note:

​Read More

Python Plotly Dash Cheat Sheet

Plotly Dash is the best Python framework for quick and easy creation of beautiful dashboard applications. To help you understand it quickly, I just finished our new Python Dash Cheat Sheet as part of our upcoming Python Dash book with NoStarch — stay tuned! You can download the PDF by clicking on the image: If

​Read More

How to Print a String Without ‘\n’ in Python

Table of Contents Strings, Printing and ‘\n’Method 1: Newlines and the Python print() functionMethod 2: The sys.stdout AlternativeMethod 3: Newlines Within the StringSummaryRelated Posts Strings, Printing and ‘\n’ The printing of a basic string is probably the first program the majority of people, myself included, write in Python –  does print(‘hello world’) sound familiar? From

​Read More

101+ Free Python Books

Spending money on books is one of the best investments you can possibly make. But why should you? This article compiles a list of 101++ FREE Python books to destroy any excuse of not learning Python. Everyone can afford to read free books! Download Your Free PDF with all the links: How To Use This

​Read More

Python Set clear()

Python’s set.clear() method removes all elements from this set. All variables that refer to this set object will refer to an empty set after calling the method. Here’s a minimal example where you remove three elements from a set at once by means of the s.clear() method: Table of Contents SyntaxReturn Value of Set clear()The

​Read More

Python Set copy()

Python’s set.copy() method creates and returns a flat copy of this set. Here’s a minimal example where you copy a set with two integers and a string value: Table of Contents SyntaxReturn Value of Set copy()Shallow vs Deep Set copy()What is the Time Complexity of Set copy()?Other Python Set MethodsRelated Posts Syntax Let’s dive into

​Read More

Python Set difference()

Python’s set.difference(element) method creates and returns a new set containing all elements of this set, except the ones in the given set argument or arguments. The resulting set has at most as many elements as any other set given in the argument list. Here’s a minimal example where we return a new set with the

​Read More

Python Set difference_update()

Python’s set.difference_update(*args) method removes all elements from this set that are members of any of the given set arguments. For example, s.difference_update({1, 2}) removes elements 1 and 2 from the set s. Its return value is None because it modifies the set it is called upon rather than creating a new set. Here’s a minimal

​Read More

Python Set add()

Python’s set.add(element) method adds the element to this set. If the element is already present in the set, the method returns without any side effect. Here’s a minimal example where we add element 4 to an existing set: Table of Contents SyntaxReturn Value of Set add()What is a Hashable Object?How to Add an Element to

​Read More

Python Set Methods

All set methods are called on a given set. For example, if you created a set s = {1, 2, 3}, you’d call s.clear() to remove all elements of the set. We use the term “this set” to refer to the set on which the method is executed. add() Add an element to this set

​Read More

Python Dash Book

We’re in the process of writing the first in-depth Python Plotly Dash book with the world’s #1 computer science book publisher NoStarch. The book appears in 2021. Stay tuned! We’ll announce the launch of the book on our email academy: Related Posts [Dash + Flask] How to Deploy a Python Dash App on Pythonanywhere.com Python

​Read More

How to Ignore Exceptions the Pythonic Way?

If you are an application developer, you might have to implement an error-free code that is well tested. In my instances, we would like to ignore I/O or Numerical exceptions. In this blog post, you will learn how we can safely ignore exceptions in Python. Imagine you are working on an application  where you have

​Read More

How to Change the Working Directory in Python

If you have worked on a Python application where you had data in another folder, you would have used a command-line tool like cd to change directories. In this tutorial, we will learn a more Pythonic way of changing directories. Table of Contents Changing directories using the os.chdir functionChanging the Working Directory using Context ManagerSummaryRelated Posts

​Read More

How to Dynamically Create a Function in Python?

Table of Contents Problem FormulationMethod 1: exec()Method 2: Function FactoryMethod 3: Function Decorator PatternMethod 4: A Function Factory ObjectRelated Posts Problem Formulation There are different variants of this problem that all ask the same thing: How to create a function dynamically in Python? How to define a function at runtime? How to define a function

​Read More

How to Display an Image as Grayscale in Python Matplotlib?

Table of Contents How to Display an Image as Grayscale in Python Matplotlib?How to Save a Grayscale Image with Matplotlib?Try It in Our Interactive Jupyter NotebookRelated Posts How to Display an Image as Grayscale in Python Matplotlib? You can convert a given image to a grayscale image using four simple steps: Import the PIL and

​Read More

Your First Dash App – How to Get Started in 4 Minutes or Less

Table of Contents Minute 1: Install DashMinute 2: Create Minimal Dash Project File “app.py”Minute 3: Run Dash AppMinute 4: Open Dash App in Your BrowserRelated Posts Minute 1: Install Dash Type the following command in your terminal/shell. Windows, macOS: Linux, Ubuntu: Minute 2: Create Minimal Dash Project File “app.py” Copy&paste the code into a new

​Read More

[Solved] TypeError: A Bytes-Like object Is Required, not ‘str’

Table of Contents Introduction📌 What is TypeError: A Bytes-Like object Is Required, not ‘str’ ?🖊️ Solution 1: Replacing ‘rb’ with ‘rt’🖊️ Solution 2: Adding prefix ‘b‘🖊️ Solution 3: Using decode() Method 🖊️ Solution 4: Using encode() Method🖊️ Solution 5: Using bytes() Method🖊️ Solution 6: Using a List Comprehension and str() MethodConclusionRelated Posts Introduction Objective: In

​Read More

How to Calculate the Levenshtein Distance in Python?

After studying this article, you will know exactly how to calculate the edit distance in Python. Learning requires opening your knowledge gap first. So let’s do this. What is the output of the following Python puzzle showing you a concise code snippet to calculate the edit distance in Python? (source) Python Source Code Now, this

​Read More

[$$$] How to Find Clients as a Python Freelancer?

Do you want to sell your coding skills as a Python freelance developer but you don’t know where to start? This article shows you the best places to look for new clients – so that you never run out of work (and $$$ cash) again. There are three types of freelancing projects: small, medium, and

​Read More

How to Determine the Type of an Object in Python?

Table of Contents Problem FormulationSolution Overviewtype() vs isinstance()Python type() FunctionPython isinstance() FunctionRelated Posts Problem Formulation Every Python object is of a certain type, also called “class”. The class is a blueprint that shows the data and capabilities of each object/instance that is created after this blueprint. Given a Python object (=instance). How to determine/check/get its

​Read More

How to Get the Number of Elements in a Python List?

Problem Formulation: Given a list of elements in Python. How to get the number of elements in the list? Examples: List Number of Elements [3, 42, 2] 3 [] 0 [‘Alice’, ‘Bob’, ‘Carl’] 3 [(1, 2), [3, 4]] 2 Table of Contents Method 1: len()Method 2: len() + set() to Count the Number of Unique

​Read More

How to Run TensorFlow in a Jupyter Notebook?

If you are a machine learning practitioner you might have come across the TensorFlow library. TensorFlow is a popular machine learning library and finds its use in a lot of AI and machine learning applications. In this tutorial you will learn How to install TensorFlow in a virtual environment How to activate your environment in

​Read More

NumPy Tutorial – Everything You Need to Know to Get Started

This tutorial gives you a simple introduction to Python’s NumPy library. You don’t need any prerequisites to follow the tutorial. My goal was to give a practical and fun NumPy introduction for absolute beginners and with many examples. By reading through this tutorial, you will gain a basic understanding of the most important NumPy functionality.

​Read More

10 Python Puzzles to Discover Your True Skill Level

Do you belong to the top 50% of Python coders? This article poses you 10 intermediate-level Python puzzles to test yourself. By solving all 10 Python puzzles and tracking your success rate, you will discover your exact Python skill level. Table of Contents The Method We Used to Measure Your Skills with Python PuzzlesWhat is

​Read More

The Math of Becoming a Millionaire in 13 Years

When I browse the web or social media, guides on how to become a millionaire pop up everywhere. If you read them, you’ll quickly find out that they’re filled with the same fluff. Let’s call it “slow-lane thinking”. Most of those guides assume you have four decades of diligent savings left. But even if you

​Read More

Extracting Numbers From A String With Python

Table of Contents A Quick Introduction To Python’s ‘re’ ModuleSo Where Would You Use Regular Expressions?Regular Expression CharactersUse The Raw String Prefix When Creating A PatternImporting And Using The Regular Expression ModuleSpecial CharactersDefine Your Own Character ClassIn SummaryRelated Posts A Quick Introduction To Python’s ‘re’ Module “How to extract digits or numbers from a string”

​Read More

How To Sort A Set Of Values?

Summary: This blog explores the steps to sort elements of a Set. Python offers the built-in sorted() function to sort elements in container objects such as a set or a list. For example: sorted({1, 5, 2}) sorts the elements in the set and returns the sorted list [1, 2, 5]. Note: All the solutions provided

​Read More