Python: Read a file in reverse order line by line
In this article we will discuss an efficient solution to read the contents of a text or CSV file in reverse order either line by line or get them as…
Python: Read CSV into a list of lists or tuples or dictionaries | Import csv to list
In this article we will discuss how to import a CSV into list. This list can be a list of lists, list of tuples or list of dictionaries. We will…
Python: How to insert lines at the top of a file?
In this article, we will discuss how to insert single or multiple lines at the beginning of a text or CSV file in python. (more…)
Python: Read a CSV file line by line with or without header
In this article we will discuss how to read a CSV file line by line with or without header. Also select specific columns while iterating over a CSV file line…
Python: Get last N lines of a text file, like tail command
In this article, we will discuss a memory-efficient solution to read the last line or last N lines from a text or CSV file in python. Then we will also…
Python: How to append a new row to an existing csv file?
In this article, we will discuss how to append a row to an existing csv file using csv module's reader / writer & DictReader / DictWriter classes. (more…)
Python: Add a column to an existing CSV file
In this article we will discuss how to add a column to an existing CSV file using and classes. A part from appending the columns we will also discuss how…
Python: How to delete specific lines in a file in a memory-efficient way?
In this article, we will discuss different ways to delete specific lines from a file either by line number, by matching content or based on any custom logic. (more…)
Python: Get file size in KB, MB or GB – human-readable format
In this article, we will discuss different ways to get file size in human-readable formats like Bytes, Kilobytes (KB), MegaBytes (MB), GigaBytes(GB) etc. (more…)
Python: Three ways to check if a file is empty
In this article, we will discuss different ways to check if a file is empty its size is 0 using () or () or by reading its first character. (more…)