Python Append to File – The Ultimate Guide

In this article, you will learn different methods to append data to a file (e.g., text file, log file, or config file) using Python. To start appending data to a file in Python, the most frequently used file modes are Each mode provides different levels of access and functionality for handling files. When working with … Read more

How to Append a Dictionary to a Non-Existent CSV File

Appending data to a CSV file is a common task in data processing. But what if the CSV file doesn’t exist yet? Here’s a step-by-step guide on how to append a dictionary to a non-existent CSV file using Python’s csv module. Prerequisites: πŸ§‘β€πŸ’» Step 1: Import CSV and OS Python Libraries πŸ§‘β€πŸ’» Step 2: Check … Read more

Organize Files by Suffix: How I Created a Python Script to Automate a Boring Task

Does the nature of your work involve going through a folder full of dozens, hundreds, or even thousands of files? What if you were told to organize those files according to their extension in a subdirectory, imagine how boring and time-consuming such a task would be if the files contain dozens of extensions! What if … Read more

Python Pickle Module: Simplify Object Persistence [Ultimate Guide]

πŸ₯’ Python pickling is another word for serializing and de-serializing Python objects, so you can store them in a binary format or transmit them across a network. Pickling helps preserving the state of objects, such as data structures or machine learning models, between different sessions or applications. The pickle module in Python’s standard library provides … Read more

This Simple Python Script Compressed My Folder of 200 Images by 700% Without Much Loss πŸš€

For my current web project I need to upload 200 images to my website. All of them are in the same folder. Here’s the problem: 🀯 Challenge: My images have file sizes of 2 to 3 MB, so they are far too big and will significantly slow down my website. πŸ‘‰ To reduce the file … Read more

I Used This Python Script to Rename All Files in Subfolders (Recursive)

I’m currently working on a website project for the Finxter ecosystem, where I’m given a folder with subfolders (and subfolders within) that contain image files. Example folder structure: folder — subfolder1 —- image1.jpg —- image2.jpg —- image3.jpg — subfolder2 —-image1.jpg —-image2.jpg Across the subfolders, the files may have the same name, which causes an issue … Read more

Generate a Simple PDF using Python ReportLab (9 Steps)

Problem Formulation and Solution Overview This article shows how to generate a formatted PDF file from a CSV file using the ReportLab and Pandas libraries in conjunction with slicing. ℹ️ Python offers numerous ways to generate a PDF file. One option is to use the ReportLab library. The article selected the path that used the … Read more

How to Write to a Binary File in Python?

Problem Formulation πŸ’¬ Question: Given a binary string in your Python script, such as b’this is a binary string’. How to write the binary string to a file in Python? For example, you may have tried a code snippet like this that will not work with file.write(): Because this yields a TypeError: Traceback (most recent … Read more