Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104650
| Path | csiph.com!feeder.erje.net!1.us.feeder.erje.net!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail |
|---|---|
| From | Grant Edwards <invalid@invalid.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: hasattr() or "x in y"? |
| Date | Fri, 11 Mar 2016 22:00:41 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 30 |
| Message-ID | <nbvf69$105$1@reader1.panix.com> (permalink) |
| References | <nbve7c$nbo$1@dont-email.me> |
| NNTP-Posting-Host | 67-130-15-94.dia.static.qwest.net |
| X-Trace | reader1.panix.com 1457733641 1029 67.130.15.94 (11 Mar 2016 22:00:41 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Fri, 11 Mar 2016 22:00:41 +0000 (UTC) |
| User-Agent | slrn/1.0.2 (Linux) |
| Xref | csiph.com comp.lang.python:104650 |
Show key headers only | View raw
On 2016-03-11, Charles T. Smith <cts.private.yahoo@gmail.com> wrote:
> From the performance point of view, which is better:
> - hasattr()
> - x in y
Dunno, is red an even or odd color? How many pancakes does it take to
cover a doghouse?
>>> "x" in "asdf"
False
>>> "x" in "xyz"
True
>>> "asdf".hasattr("x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'hasattr'
>>> "xyz".hasattr("x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'hasattr'
Since they behave differently, perhaps the question ought to be "which
does what you want to do?"
--
Grant Edwards grant.b.edwards Yow! I had pancake makeup
at for brunch!
gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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