Blog

python tutorials and learn python

Created with Sketch.

Python Write Text File

Python Write Text File Summary: in this tutorial, you’ll learn various ways to write text files in Python. TL;DR The following illustrates how to write a string to a text file: with open(‘readme.txt’, ‘w’) as f: f.write(‘readme’) Code language: JavaScript (javascript) Steps for writing to text files To write to a text file in Python,…
Read more

Python Read Text File

Python Read Text File Summary: in this tutorial, you learn various ways to read text files in Python. TL;DR The following shows how to read all texts from the readme.txt file into a string: with open(‘readme.txt’) as f: lines = f.readlines() Code language: Python (python) Steps for reading a text file in Python To read…
Read more

Python Delete File

Python Delete File Summary: in this tutorial, you’ll learn how to delete a file from Python using the os.remove() function. To delete a file, you use the remove() function of the os built-in module. For example, the following uses the os.remove() function to delete the readme.txt file: import os os.remove(‘readme.txt’) Code language: Python (python) If…
Read more

Python Rename File 

Python Rename File Summary: in this tutorial, you’ll learn how to rename a file using the os.rename() function. To rename a file, you use the os.rename() function: os.rename(src,dst) Code language: CSS (css) If the src file does not exist, the os.rename() function raises a FileNotFound error. Similarly, if the dst already exists, the os.rename() function…
Read more

Python Write CSV File

Python Write CSV File Summary: in this tutorial, you’ll learn how to write data into a CSV file using the built-in csv module. Steps for writing a CSV file To write data into a CSV file, you follow these steps: First, open the CSV file for writing (w mode) by using the open() function. Second,…
Read more

Python Read CSV File

Python Read CSV File Summary: in this tutorial, you’ll learn how to read a CSV file in Python using the built-in csv module. What is a CSV file CSV stands for comma-separated values. A CSV file is a delimited text file that uses a comma to separate values. A CSV file consists of one or…
Read more

Python Check If File Exists

Python Check If File Exists Summary: in this tutorial, you’ll learn how to check if a file exists. When processing files, you’ll often want to check if a file exists before doing something else with it such as reading from the file or writing to it. To do it, you can use the exists() function…
Read more

Python Create Text File

Python Create Text File Summary: in this tutorial, you’ll learn how to create a new text file in Python using the open() function. Using the open() function to create a new text file To create a new text file, you use the open() function. The open() function has many parameters. However, we’ll focus on the…
Read more

Python Write Text File

Python Write Text File Summary: in this tutorial, you’ll learn various ways to write text files in Python. TL;DR The following illustrates how to write a string to a text file: with open(‘readme.txt’, ‘w’) as f: f.write(‘readme’) Code language: JavaScript (javascript) Steps for writing to text files To write to a text file in Python,…
Read more

Python Read Text File

Python Read Text File Summary: in this tutorial, you learn various ways to read text files in Python. TL;DR The following shows how to read all texts from the readme.txt file into a string: with open(‘readme.txt’) as f: lines = f.readlines() Code language: Python (python) Steps for reading a text file in Python To read…
Read more