Adam Getchell wrote:
I should add that I don't really see the benefit of using a variable for your 'Contents' here. I think it would be more natural (i.e., more like my preferred style ;) ) to store the file object instead of the xreadlines object:def CalculateSquidIpHits(logfile_pathname): # Make a dictionary to store IP addresses and their hit counts # and read the contents of the log file line by line IpHitListing = {} Contents = open(logfile_pathname, "r").xreadlines()for line in Contents:
logfile = open(logfile_pathname, "r")
for line in logfile.xreadlines():
[....]
Or even do the whole thing in a single line:
for line in open(logfile_pathname, "r").xreadlines():
[....]
However, these are stylistic issues and thus largely a matter of personal preference. Personally, I'd prefer the first method, since that also allows you to explicitly logfile.close() when you're done. Files are usually automatically closed by the garbage collector when the open-file object is destroyed, so it's usually fairly safe to not explicitly close files, but under some circumstances (e.g., running in Jython) the file object may never be finalized. On the principle that explicit is better than implicit, I prefer to close() files even when I know I'm running in an environment that will allow them to be implicitly closed.
Jeff Shannon
Technician/Programmer
Credit International
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython