Skip to content
Advertisement

How to check whether a file is empty or not

I have a text file. How can I check whether it’s empty or not?

Advertisement

Answer

>>> import os
>>> os.stat("file").st_size == 0
True
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement