How to determine if a file is empty in Python

藏色散人
Release: 2019-10-17 15:43:46
Original
9993 people have browsed it

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('文件不是空的')
Copy after login

Related recommendations: "Python Tutorial"

Usage of Python function os.path.getsize()

Get the file size:

os.path.getsize(filename)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!