Message230692
| Author |
ethan.furman |
| Recipients |
Jim.Jewett, Joshua.Chin, ethan.furman, pitrou, r.david.murray, rhettinger |
| Date |
2014年11月05日.16:04:33 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1415203473.75.0.619690692422.issue22766@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Raymond declared:
----------------
> Let's be clear. These are duck-typed methods. A type check is inappropriate.
> Anything with o.items() is allowed regardless of type.
Wikipedia explains (http://en.wikipedia.org/wiki/Duck_typing):
-------------------------------------------------------------
> In computer programming with object-oriented programming languages, duck typing
> is an alternative to typing. In duck typing, an object's suitability for some
> purpose is determined by the presence of certain methods and properties [...]
I did use an actual 'type' check in one of my exmaples, and that was wrong.
It is possible to do a "duck-type check" with a `hasattr(other, 'items')`.
I don't use Counter myself -- I'll try and find some real-world examples. |
|