TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelLinuxPython

How to check file is empty or not using Python

In-order to check a file is empty or not, we can use the os functionality in Python.

import os
if os.stat("file-name").st_size == 0:
    print "File is empty"
else: 
    print "File is not empty"

Here we need to replace the 'file-name' with the name of the file that we need to check.

Leave a Reply