grahn+nntp at snipabacken.dyndns.org
Sat Sep 2 20:01:17 CEST 2006
On Sat, 2 Sep 2006 13:22:59 +0200, Sybren Stuvel <sybrenUSE at YOURthirdtower.com.imagination> wrote:
> DarkBlue enlightened us with:
>> Following code works .
> No it doesn't - it's indented badly. I guess you mean something like:
> def activeip(checkip):
> # if there is any line returned we set activeb to 1 indicating that
> # this ip is active during a netstat run
> for line in os.popen("netstat -a -n | grep '%s'" % checkip) :
> if s <>'' :
> return activeb
> Also try to use != instead of <>. Being equal or not has nothing to do
> with being larger or smaller.
Yeah, that took me a few seconds to mentally convert to !=. Personally, I'd
just write "if line:" in this case.
While we're at it, please write the documentation from a /user/ standpoint,
not as internal scribblings. And don't call the address 'checkip' -- that
makes it look like you pass a functor to the function. Maybe something like
| def ip_is_active(addr):
| """Return success if 'addr' shows up in the output from 'netstat -an'.
| We assume that a suitable version of netstat exists.
This doc string is vague -- but that's because it's unclear what the
function does and what you expect it to do. I see half a dozen problems or
so, but that might be ok if its callers don't expect too much.
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
More information about the Python-list