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

How to Assign the Result of exec() to a Python Variable?

πŸ’¬ Question: Say you have an expression you want to execute using the exec() function. How to store the result of the expression in a Python variable my_result? Before I show you the solution, let’s quickly recap the exec() function: Recap Python exec() Python’s exec() function executes the Python code you pass as a string … Read more

How to Add a Column to a CSV

Problem Formulation and Solution Overview In this article, you’ll learn how to add a new column to a CSV file in Python. To make it more fun, we have the following running scenario: The owner of the Finxter Academy has asked you to add a new column to their existing CSV file called Total_Chrgs. πŸ’¬ … Read more