[Twisted-Python] SMTP patch

Andrew Bennetts andrew-twisted at puzzling.org
Thu May 22 21:13:35 MDT 2003


On Thu, May 22, 2003 at 11:02:53PM -0400, Jp Calderone wrote:
> On Fri, May 23, 2003 at 11:05:24AM +1000, Andrew Bennetts wrote:
> > On Thu, May 22, 2003 at 04:48:35PM +0200, Anders Hammarquist wrote:
> > > Make sure to drop any references to the file object containing the
> > > message data.
> > > 
> > 
> > > +        if code in xrange(200,300):
> > 
> > I think a much better way to do this is:
> > 
> >     if 200 <= code <= 300:
> > 
> 
>     Interestingly, there was a thread on PyPy-dev on this subject.  I think
> I agree with the line of thinking that says "x in y" expresses the intent
> more accurately and at a higher level than "a <= x < y".  xrange() is a hack
> though, so I would use range() :)

Oops!  As you imply, that should've been "200 <= code < 300".  I still don't
like the idea of constructing 100 integers, even lazily, just to test
bounds, though.

Of course, if the status code was left as a string, then you could simply do
"if code.startswith('2'):"  :)

-andrew.





More information about the Twisted-Python mailing list