Checking if a text file is blank

prashanth munichlinux at news.motzarella.org
Sun Apr 20 06:46:12 EDT 2008


Hi

elnoire at gmail.com 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 f.read() 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.




Prashanth



More information about the Python-list mailing list