Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104653

Re: hasattr() or "x in y"?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From "Charles T. Smith" <cts.private.yahoo@gmail.com>
Newsgroups comp.lang.python
Subject Re: hasattr() or "x in y"?
Date Fri, 11 Mar 2016 22:18:51 -0000 (UTC)
Organization A noiseless patient Spider
Lines 17
Message-ID <nbvg8a$vcv$1@dont-email.me> (permalink)
References <nbve7c$nbo$1@dont-email.me> <nbvf69$105$1@reader1.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Fri, 11 Mar 2016 22:18:51 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="177e1664974e843811fc618206653a33"; logging-data="32159"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/356Ovf4tUXGg/mLwaIf2HthNDO7aPYPY="
User-Agent Pan/0.133 (House of Butterflies)
Cancel-Lock sha1:Flm4YHzfN2jXHscvGJtZ1/+qkZ0=
Xref csiph.com comp.lang.python:104653

Show key headers only | View raw


On Fri, 11 Mar 2016 22:00:41 +0000, Grant Edwards wrote:

> Since they behave differently, perhaps the question ought to be "which
> does what you want to do?"

For parsed msgs, I had this:

              elif hasattr (msg.msgBody, 'request'):

It occurred to me that this was less abstruse:

              elif 'request' in msg.msgBody:

and by the way, how would you do that with duck-typing?
If I were doing this anew, I probably use a dictionary of functors,
but that's not an option anymore.
              

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

hasattr() or "x in y"? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 21:44 +0000
  Re: hasattr() or "x in y"? Chris Angelico <rosuav@gmail.com> - 2016-03-12 08:55 +1100
  Re: hasattr() or "x in y"? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 21:53 +0000
    Re: hasattr() or "x in y"? Chris Angelico <rosuav@gmail.com> - 2016-03-12 09:04 +1100
    Re: hasattr() or "x in y"? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-11 22:05 +0000
  Re: hasattr() or "x in y"? Grant Edwards <invalid@invalid.invalid> - 2016-03-11 22:00 +0000
    Re: hasattr() or "x in y"? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 22:18 +0000
      Re: hasattr() or "x in y"? Grant Edwards <invalid@invalid.invalid> - 2016-03-11 22:30 +0000

csiph-web