[Tutor] Compute data usage from log

Dave Angel davea at ieee.org
Tue Oct 27 17:24:51 CET 2009


(For some reason you keep top-posting.  Add your comments to the end, or 
inline if appropriate)

bibi midi wrote:
> Yep it works! I understand now it iterates on each line and replaces the old
> elements with the new ones. In the end you get the latest date of the last
> line of log.
>
> I will work on the exception handling and other refinements. Thanks.
>
>
>
> On Tue, Oct 27, 2009 at 8:41 AM, Christian Witts <cwitts at compuscan.co.za>wrote:
>
>   
>> <snip>
>>     
>>>    for line in open(log_file):
>>>      last_log_date = ' '.join(line.split(' ')[:3]
>>>
>>>       
>
In an earlier example, you already had a for loop on the log_file so the 
last line would still be in the variable "line".  If you put the date 
logic right after the loop, there'd be nothing wrong with using the last 
line that way.   Beats going back through the file and repeating it all 
again.

DaveA


More information about the Tutor mailing list