How to check whether a file is empty or not
Both getsize()
and stat()
will throw an exception if the file does not exist. This function will return True/False without throwing (simpler but less robust):
import osdef is_non_zero_file(fpath): return os.path.isfile(fpath) and os.path.getsize(fpath) > 0