I have a text file.
How can I check whether it's empty or not?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
if for some reason you already had the file open you could try this:
if you have the file object, then
Ok so I'll combine ghostdog74's answer and the comments, just for fun.
False
means a non-empty file.So let's write a function:
Both
getsize()
andstat()
will throw an exception if the file does not exist. This function will return True/False without throwing: