Advertisement
steve-shambles-2109

Python code snippets vol 33: 164-Checking if a file is empty

Oct 13th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. """
  2. Python code snippets vol 33:
  3. 164-Checking if a file is empty
  4. stevepython.wordpress.com
  5.  
  6. source:
  7. Based on a Python Notes for professsionals entry. Page 195.
  8. https://books.goalkicker.com/PythonBook/
  9. """
  10. import os
  11.  
  12.  
  13. def is_empty_file(your_file):
  14.     '''check if file exists, and if so check if empty returns bool value'''
  15.     return os.path.isfile(your_file) and os.path.getsize(your_file) == 0
  16.  
  17. print(is_empty_file("test.txt"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement