tags:

views:

663

answers:

2

I have text file, how check whether it's empty or not?

+15  A: 
import os    
os.path.getsize(fullpathhere) > 0
Jon
For safety you may need to catch `OSError` and return False.
KennyTM
+3  A: 
>>> import os
>>> os.stat("file")[6]==0
True
ghostdog74
`stat.ST_SIZE` instead of 6
wRAR
that's fine too. but i don't want to import stat. Its short and sweet enough and the size position in the returned list is not going to change anytime soon.
ghostdog74
@wRAR: os.stat('file').st_size is even better
Daniel Stutzbach