How to Get File Extension in Python?

python get file type

When I was working on a project, I had to process hundreds of files stored in a shared folder. The challenge was simple: I needed to identify file extensions before performing any operation. At first, I thought Python would have an easy function for it. However, I soon realized that there are multiple ways to … Read more >>

How to Get Filename From Path in Python

Python File Name Using Os Module

The challenge I faced while working on a project was: I needed only the filename, not the full directory path. If you’ve ever worked with file systems in Python, you know how often this comes up. For example, when processing reports from multiple states in the USA, you may have file paths like: But in … Read more >>

How to Create a Python File in Terminal?

Create a Python File in Terminal

In this tutorial, I will explain how to create a Python file in terminal. As a programmer, you often come across creating files and it is important to learn how to create a file in terminal. After researching I found several ways to achieve this task. I will explain the whole process step-by-step with examples … Read more >>

How to Check if a File Exists in Python?

Check if a File Exists in Python

As a developer working on a project for a client in the United States, I recently encountered a situation where I needed to verify the existence of a file before processing it. In this tutorial, I will explain how to check if a file exists in Python using various methods. I will share my experience … Read more >>

Python Get Current Directory: os.getcwd() and Path.cwd()

Python get current directory: Command Prompt showing the working directory differs from the script folder so open fails

Call os.getcwd() to get the current directory in Python. It returns the working directory as a string, and Path.cwd() from pathlib gives you the same folder as a Path object: One catch trips up almost everyone: that’s the folder you launched Python from, not the folder your script sits in. I’ll show both, with real … Read more >>

Build an Image-to-PDF Converter in Python

Build an Image-to-PDF Converter in Python

When I work with scanned documents, screenshots, receipts, or batches of photos, converting each image manually into a PDF quickly becomes repetitive. A small Python desktop application solves that problem nicely. For this project, I wanted more than a simple image-to-PDF script. The application needs a graphical user interface, multiple image selection, image ordering, validation, … Read more >>

How to Print a New Line in Python (Including After a Variable)

Python print new line: Command Prompt showing that printing a newline character with print produces two line breaks

Python’s print() ends every call with a new line, so printing a new line in Python usually means doing nothing extra. Call print() on its own for a blank line, or put \n inside the text: The details trip people up, though, starting with print("\n") giving two line breaks. Every output here is a real … Read more >>

How to Print a Tuple in Python

print tuple python

I have found that tuples are one of the most reliable ways to store fixed data. Whether I am handling GPS coordinates for a logistics app or storing a set of tax brackets, I often need to display this data clearly. Printing a tuple might seem like a “Day 1” task, but there are several … Read more >>

How to Print an Array in Python: A Step-by-Step Guide

How to Print an Python Array

Last year, a small HR team I worked with was still tracking employee leave in a shared Excel sheet. Every time someone requested vacation or sick time, someone had to open the file, scroll through rows, and manually check for overlaps. It worked until three people requested the same week off, and it wasn’t caught … Read more >>