file size 'mystery'

Sven Brandt sven_NOSPAM at manastar.de
Tue May 20 10:26:38 EDT 2003


Hi,

I'd like to determin the size of a file an do stuff at a certain size 
(here > 0 byte). In Python:

   my_file=open(some_file)      # some_file has size of 1000 byte

   print len(my_file.read())    # prints 1000
   x=len(my_file.read())

   if len(my_file.read()) > 0:
     print len(my_file.read())  # prints 0

   return printed


The script returns
1000
0

Why is the file size different in the if-clause? (I'm using Python 2.1 
through Zope 2.6.1).

Regards
Sven





More information about the Python-list mailing list