Checking if a text file is blank

prashanth munichlinux at
Sun Apr 20 12:46:12 CEST 2008


elnoire at wrote:
> Greetings!
>  Is there any way in python to check if a text file is blank?

obviously there are many ways, one simple way is to check length if its 
None then the file is blank.

> What I've tried to do so far is:
>                 f = file("friends.txt", "w")
> 		if is True:
> 			"""do stuff"""
> 		else:
> 			"""do other stuff"""
> 		f.close()

If checking the file is blank is what you are tying to do then why do 
you open the file in the write mode.


More information about the Python-list mailing list