import os
# Print out 'File is empty!' if nodata.txt is empty if os.path.getsize('nodata.txt') == 0: print("File is empty!")
If nodata.txt was empty the code above would output File is empty.
You can try this yourself below. Try changing 'nodata.txt' to 'data.txt' in line 3 and you will get a different output.
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.