Home > Article > Backend Development > How to determine if a file is empty in Python
How does python determine if a file is empty?
Get the file size. If the file size is equal to 0, it is empty, as follows:
import os size = os.path.getsize('d:/abc.txt') if size == 0: print('文件是空的') else: print('文件不是空的')
Related recommendations: "Python Tutorial"
Usage of Python function os.path.getsize()
Get the file size:
os.path.getsize(filename)
The above is the detailed content of How to determine if a file is empty in Python. For more information, please follow other related articles on the PHP Chinese website!