Grokbase Groups Python tutor May 2005

At 04:17 PM 5/13/2005, Alan Gauld wrote:
AS a general pont all uppercase usually means a consrtant in Python.
Variable names typically start lowercase and either use capital
letters to separate words likeThis, or use underscores like_this.

Variables starting with an uppercase letter tend to indicate class
names - although thats not universally true, even in the standard
library! But the ALLUPPER thing for constants is pretty universal
so its worth adopting IMHO.
Thanks for the style pointers. I will make these changes -- I realize how
important consistency is, since I use other people's code as a learning
tool with great frequency.
So what happens? Do you get any error messages?
What value is CLAM_RESULT showing?
What value are you expecting? (The actual return value from
popen/close is not clearly defined in general.)
Finally, although you close the pipe it may be worth trying
a flush() first just to clear the buffer.
I have gotten this working, with much help (especially from Danny). Here
is what the code I settled on looks like:

working = email.message_from_file(open(emailfile))

clamav = popen2.Popen3(clamav_cmd,1)
clamav_result ='stream: ')
clamav_exit = os.WEXITSTATUS(clamav.wait())

This gives me a string (clamav_result) that contains the output from the
scanner: either OK if it was clean, or the name of the virus
detected. (it is prefixed with "stream: " to indicate that stdin was
scanned, so I strip that off)
clamav_exit contains the exit code, converted using WEXITSTATUS: either 0,
1, or 2 for OK, infected, or error respectively.

This seems to be working out just fine, and gives me a lot more flexibility
that the bash script I was using! (as a note, I am reading the email into
an email object because I perform other actions, like adding
headers. Otherwise, it would be simpler to have clamav read the file
directly rather than the stream.)

Thanks to everyone for your patience and advice!


* * * * * * *
Jeffrey Rice || jeffrice at ||

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 5 | next ›
Discussion Overview
grouptutor @
postedMay 12, '05 at 4:39a
activeMay 16, '05 at 12:18a

2 users in discussion

Jeffrey Rice: 3 posts Danny Yoo: 2 posts



site design / logo © 2022 Grokbase