Practical solutions

Python How-To's How-To Guides

Solve the problem. Keep building. The collection of Python-related howtos

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Resize Image While Maintaining Its Aspect Ratio in PythonThis article demonstrates about how to resize an image in Python and maintain its aspect ratios. How to Pass Kwargs to Another Function in PythonPython denoted kwargs arguments as a keyword arguments which can be pass number of arguments using two asterisks before parameter name. Through this article we look for how Python pass kwargs to another function. How to Get The Next Item in Python for LoopThis article discussed for loops in Python and how to a list skipping its first element by using for loop along with examples. How to Find the Last Day of the Month Using PythonThis article uses four distinct libraries, two inbuilt - Calendar and DateTime, and two third-party - Arrow and Pandas to find the last day of a given month. The article provides various examples explaining the same and decoding the logic behind each example. How to Sort Date and Time in PythonIn this article, we discuss how to sort date and time using sorted() method in Python. To understand the concept, we have taken some examples along with the datetime module in Python. How to Mock Return Value Based on Input in PythonThis article demonstrates about mock return value based on input in Python. How to Generate Random 4 Digit Number in PythonIn this article, we discuss how to generate random four-digit numbers with Python. Mainly we learn two methods: randint() and randrange() that can use to generate random four-digit numbers easily. Apart from that, we learn an alternative method to achieve it. How to Calculate the Average Word Length in a Sentence in PythonThis tutorial will teach you to calculate the average word length in a sentence in Python. How to Mock Patch One Function Invoked by Another Function in PythonThis tutorial educates about mock objects and their importance and uses patch() as a decorator, a context manager and manually start/stop to demonstrate how to mock patch one function invoked by another function. How to Round Up to the Nearest Ten in PythonThis article will discuss the methods on rounding a number to the nearest ten in Python. How to Mock Python ImportThis article demonstrates how to use Python Mock Import. How to Fix Python Handling Socket.Error: [Errno 104] Connection Reset by PeerThis tutorial will take us through all we need to know about the connection reset by peer error and the best way to handle it. How to Append Data to a JSON File Using PythonThis tutorial demonstrates the use of Python dictionary and list to append data to a JSON file using Python. How to Get Longest Increasing Subsequence in PythonWe will learn what is a subsequence and how to calculate the longest increasing subsequence from an array using the n-squared approach and the binary search approach in Python. How to Capture Output in Python SubprocessThe main aim of this article is to demonstrate how can the output of a subprocess be captured, stored and shown in Python. How to Read Stdout While Running in Python SubprocessThe main aim of this article is to demonstrate how to read the stdout of a subprocess being executed in Python. How to Install Python Module Within CodeThere are more than one way to do things, we want to use this tutorial to learn how to use codes to install Python modules. How to Get CPU Temperature using PythonThe main aim of this article is to demonstrate how to read and show CPU temperature with the help of the pythonnet library in Python. How to Extract Table From Webpage in PythonThe main aim of this article is to demonstrate how tables can be extracted from a webpage using Pandas and lxml in Python. How to Use Gnuplot With PythonIn this article, we will discuss Gnuplot and how we plot data in Gnuplot using Python. Furthermore, we will discuss the installation and use of Gnuplot and PyGnuplot packages in Python. How to Validate Phone Number in PythonThis article demonstrates phone number validation in Python. How to Insert Data Into an SQLite Database Using PythonThis tutorial introduces how to use the sqlite3 module to insert data in a table which resides in SQLite database. How to Print Binary Tree in PythonThis article demonstrates how to print a binary tree using Python. How to Fit a Step Function in PythonStep functions are methods with graphs that look like a series of steps. They consist of a series of horizontal line segments with intervals in between and can also be referred to as staircase functions. This article demonstrates using the step function in Python and plotting the graph.