Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5230
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!panix!roy |
|---|---|
| From | Roy Smith <roy@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | list equal to subclass of list? |
| Date | Thu, 12 May 2011 08:23:04 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 37 |
| Message-ID | <roy-B4A109.08230412052011@news.panix.com> (permalink) |
| NNTP-Posting-Host | localhost |
| X-Trace | reader1.panix.com 1305202986 264 127.0.0.1 (12 May 2011 12:23:06 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Thu, 12 May 2011 12:23:06 +0000 (UTC) |
| User-Agent | MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5230 |
Show key headers only | View raw
I have a vague feeling this may have been discussed a long time ago, but
I can't find the thread, so I'll bring it up again.
I recently observed in the "checking if a list is empty" thread that a
list and a subclass of list can compare equal:
----------------------------
class MyList(list):
"I'm a subclass"
l1 = []
l2 = MyList()
print type(l1), type(l2)
print type(l1) == type(l2)
print l1 == l2
----------------------------
when run, prints:
<type 'list'> <class '__main__.MyList'>
False
True
The docs say:
[http://docs.python.org/library/stdtypes.html]
Objects of different types, except different numeric types and different
string types, never compare equal
[http://docs.python.org/release/2.7/reference/expressions.html#notin]
objects of different types (emphasis)always compare unequal
In the test code above, l1 an l2 are different types, at least in the
sense that type() returns something different for each of them. What's
the intended behavior here? Either the code is wrong or the docs are
wrong.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 08:23 -0400
Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 09:43 -0700
Re: list equal to subclass of list? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-13 00:18 +0000
Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 18:04 -0700
Re: list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 21:53 -0400
Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 11:29 -0700
Re: list equal to subclass of list? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-12 22:40 +0200
Re: list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 13:49 -0700
Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 14:48 -0700
csiph-web