How to Erase Contents of a File

Problem Formulation and Solution Overview In this article, you’ll learn how to erase the contents of a file in Python. To make it more fun, we have the following running scenario: Let’s say you have a Python script that retrieves the daily stock exchange prices for five (5) Tech Companies and saves it to prices.txt. … Read more

Python Getpass Module: A Simple Guide + Video

The Python getpass module provides portable password input functionality and allows you to accept an input string in a command-line interface (CLI) without the string being typed from being visible (echoed) in the interface. The getpass module also includes a getuser function for retrieving a username from the relevant environment variables. In this getpass Python … Read more

How to Open Multiple Files in Python

Problem Formulation and Solution Overview In this article, you’ll learn how to open multiple files in Python. πŸ’¬ Question: How would we write Python code to open multiple files? We can accomplish this task by one of the following options: Method 1: Open Multiple Text Files using open() Method 2:Open Multiple Text Files using open() … Read more

Computer Science Researcher – Income & Opportunity

Before we learn about the money, let’s get this question out of the way: What Does a Computer Science Research Scientist Do? A computer science researcher and scientist identifies and answers open research questions in computer science. They apply scientific reasoning and research techniques to push the state-of-the-art forward in various fields such as machine … Read more

Embedded Applications Engineer — Income and Opportunity

Before we learn about the money, let’s get this question out of the way: What is an Embedded Applications Engineer? An embedded systems engineer applies software development and embedded systems knowledge to design, create, develop, debug, and maintain embedded applications and products. Other terms with similar job descriptions are often used interchangeably: Embedded systems engineer … Read more

How to Search for Specific Files Only in Subdirectories in Python?

[toc] Problem Formulation: Let’s say we have a directory containing other subdirectories which further contain files. How do we search for a specific file in the subdirectories in our Python script? Scenario: We have a parent folder (Parent) with child folders (child_1, child_2, and child_3). There are files in the parent directory/folder as well as … Read more

Extract File Name From the Path, No Matter What the os/path Format

Summary: os.path.basename(path) enables us to get the file name from the path, no matter what the os/path format. Another workaround is to use the ntpath module, which is equivalent to os.path. ✨Problem: How to extract the filename from a path, no matter what the operating system or path format is? For example, let’s suppose that … Read more

How To Get The Filename Without The Extension From A Path In Python?

[toc] Problem Statement: How to get the filename without the extension from a path in Python? Example: Suppose you have a file with the following path: C:\Users\SHUBHAM SAYON\Documents\folder1 Here, we just need to get the filename, i.e. “demo“.  In Python, files are used to store information.  We can perform many operations on the files- read, write, … Read more

How to Write Huge Amounts of Generated Data to a File in Python?

Problem formulation Sometimes we need to generate massive amounts of data. For example, to perform bootstrapping or jackknifing of our actual data. To get lots of parameterized dummy data, learn how to use new libraries or adjust the model’s hyperparameters. Or benchmark different solutions or debug and optimize our code. Generating this data is expensive, … Read more

Choose A File Starting With A Given String

Overview Problem: How to choose a file starting with a given string? Example: Consider that we have a directory with files as shown below. How will you select the files starting with “001_Jan“? Python Modules Cheat Sheet To Choose A File Starting With A Given String Choosing a file starting with a given string is … Read more