Reading a file line by line with Python
Python is a popular scripting language that is widely used for data analysis, automation, and web development. By reading a file line by line with Python, you can process large […]
Executing shell commands with Python
When working with Python, there may be times when you need to execute shell commands directly from your Python code. This can be particularly useful for automating tasks, managing system […]
Writing to files with Python
Python provides several ways to write data to a file, including using the built-in open() function and the with statement. In this article, we’ll cover how to write to a […]
Reading and Writing XML Files in Python with Pandas
XML files are a common data format used for exchanging data between different systems. Python provides several libraries for parsing and manipulating XML files, including the popular xml.etree.ElementTree module. In […]
How to Work with PostgreSQL in Python?
PostgreSQL is a popular open-source relational database management system. It offers many advanced features and is widely used in production environments. Python is a powerful programming language that is also […]
Flatten an irregular list of lists in Python
Let’s say I would like to flatten an irregular list of lists. First approach is by using collections.Iterable where x is the irregular list of lists. Second approach is a […]
Split a list into evenly sized chunks in Python
where l is the list and n is the number of items in a chunk. Use xrange() instead of range() in the case of Python 2.x
Create a flat list out of a list of lists in Python
Let’s take a list of lists. To merge this lists to a flat list you can use the following ways. itertools.chain() functools.reduce() list.extend()
TypeError: ‘str’ object does not support item assignment – Python error – How to fix?
Python strings are immutable and they cannot be changed during the course of Python program execution. In Python, strings cannot be modified. You need to create a new string based […]
Play a Youtube video using pywhatkit in Python
The playonyt() function in pywhatkit module is used to play a Youtube video either from a URL or from a keyword. Syntax Example
Convert YYYYMXX to date in pandas dataframe in Python
How to clear a list in Python?
To clear/empty a list in Python, we can use the predefined clear() method. Another way to empty a list is by using slicing.
How to check if a list is empty in Python?
In this tutorial we discuss the various ways of checking if a list is empty in Python. len bool equal
Scraping using Python and BeautifulSoup4
This tutorial is a blast from the past. I wrote this script 5 years back to learn web scraping and to my surprise it still works. I’ll walk you through […]
Convert wav to mp3 format in Python
Learn how to convert an audio file from wav format to mp3 format in Python. Pydub is a Python module that can be used in Audio manipulation. pydub can be […]
How to create nested directory in Python 3.5+?
Learn how to create nested directories in Python safely without errors. We can make use of the pathlib library and its .mkdir() method to safely create a nested directory. Import […]
Creating Interactive Corona Virus(COVID-19) Tracking Dashboard using Python
Learn how to build an interactive dashboard to track live status of Corona pandemic across the world using public APIs and Python. A good visualization conveys the true meaning hidden […]
Reading a file line by line in Python
In this article we will discuss different ways to read a file line by line in Python. In Python, there is no need for importing external library for file handling. […]
Check if variable exists in Python
How to check if a variable exists in Python ? Python doesn’t have a specific function to test whether a variable is defined, since all variables are expected to have been defined before use, even if initially assigned the None object. The […]
Sending email in Python
How to send email in Python? There are many ways to acheive this: smptlib, sendmail or even Gmail SMTP port can be used. Read on to know how. smtplib The smtplib is […]
Install Python 3.8 on Ubuntu
Python 3.8.0 is the newest major release of the Python programming language, and it contains many new features and optimizations. This tutorial helps you install Python 3.8 on Ubuntu. Major […]
How to print in same line in Python?
One annoying thing about print() function is, it automatically prints a newline ‘\n’ at the end of the line! print() function was added in Python 3. Until Python 2, print() […]
How to get hostname in Python?
There are a few different ways to get the hostname of a system in Python. The socket module in Python gives access to the BSD socket interface. It is accessible […]
How to generate random numbers in Python?
Randomness plays an important role in the evolution of machine learning algorithms. Python defines a set of functions that are used to generate or manipulate random numbers. This particular type […]