get the size of a dynamically changing file fast ?

Stef Mientki stef.mientki at gmail.com
Wed Jan 23 13:16:58 EST 2008


>>>> thanks Mike,
>>>> sorry for the late reaction.
>>>> I've it working perfect now.
>>>> After all, os.stat works perfectly well,
>>>> the problem was in the program that generated the file with increasing
>>>> size,
>>>> by truncating it after each block write, it apperently garantees that
>>>> the file is flushed to disk and all problems are solved.
>>>>         
>>>> cheers,
>>>> Stef Mientki
>>>>         
>>> I almost asked if you were making sure you had flushed the data to the
>>> file...oh well.
>>>       
>> Yes, that's a small disadavantage of using a "high-level" language,
>> where there's no flush available, and you assume it'll done
>> automatically ;-)
>>
>> cheers,
>> Stef
>>     
>
> Uhm, there is a flush method for Python's files.  From "http://
> docs.python.org/lib/bltin-file-objects.html":
> flush()
>     Flush the internal buffer, like stdio's fflush(). This may
>     be a no-op on some file-like objects.
>
> As for an example:
>
>   
>>>> import os
>>>> f = open('vikings.txt', 'wb')
>>>> os.stat('vikings.txt').st_size
>>>>         
> 0L
>   
>>>> f.write('Spam, spam, spam, spam!  ' * 1000)  # Bloody vikings...
>>>> os.stat('vikings.txt').st_size
>>>>         
> 24576L
>   
>>>> f.flush()
>>>> os.stat('vikings.txt').st_size
>>>>         
> 25000L
>   
>
> Is there something that I'm missing here?
>
>   
hi Jason,
I was talking about a "high-level" language, in which the sending 
program was written,
(Delphi, not about Python ;-)
cheers,
Stef




More information about the Python-list mailing list