There is a simpler way to check.
If you use pathlib to open files, you can use:
If you use pathlib to open files, you can use:
from pathlib import Path import os # make sure in proper directory (this sets dir same as script) os.chdir(os.path.abspath(os.path.dirname(__file__))) # example file filename = Path("myfile.txt") if filename.stat().st_size: print("file has size") else: print("file is empty")if not using pathlib, use instead:
import os # make sure in proper directory (this sets dir same as script) os.chdir(os.path.abspath(os.path.dirname(__file__))) # example file filename = "myfile.txt" if os.stat("myfile.txt").st_size: print("file has size") else: print("file is empty")