creating my own logwatch in python

Mahmoud Abdelkader mabdelkader at gmail.com
Fri Jul 17 18:33:55 EDT 2009


A few code critiques:
 -  Your code is not very help friendly because it can not be run, so I have
to deadlist debug it.
 -  There are various syntax errors in the code:
    - for example: file is not defined when you invoke tail(file)
 -  You are overshadowing a built-in type 'file' by that name, which is
confusing. PEP 8 states that if you want to use a keyword, the practice is
to put an underscore after it. So, it should become file_
 -  Getopt is very old and should not be used. You should use the better,
readable, optparse
 -  That while loop will consume 99% CPU because of the infinite loop
 -  line = file.readline() is guaranteed to return a newline OR an empty
string ONLY when an EOF is encountered since you're not specifying the
optional maximum read byte size. This means that all your characters are
strings. So, why do you explicitly convert each character to a string and
separate each character by a space? (line 18)
 - Line 19 will always return 0 because of line 18
 - Line 19->22 are completely redundant, since readline is guaranteed to
give you ONE line. You should just do if "uccess" in logString: ...

Hope this helps,
mahmoud mack abdelkader
http://blog.mahmoudimus.com/



On Fri, Jul 17, 2009 at 5:58 PM, LoD MoD <lodmod.dod at gmail.com> wrote:

> I am trying to fabricate a logwatch-type script in Python and I'm having
> some trouble.What happens with the following code is that it prints to the
> screen but the if condition on line 22 never gets executed.
>
> http://pastie.org/549975
>
> Any suggestions are appreciated.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090717/084f8280/attachment-0001.html>


More information about the Python-list mailing list