"Martin v. Loewis" wrote: > > > i don't see an easy way to test if something supports one of these > > abstract interfaces in Python. > > Why do you want to test for that? If you have an algorithm that only > operates on integer-indexed things, what can you do if the test fails? > > So it is always better to just use the object in the algorithm, and > let it break with an exception if somebody passes a bad object. Right. Polymorphic code will usually get you more out of an algorithm, than type-safe or interface-safe code. BTW, there are Python interfaces to PySequence_Check() and PyMapping_Check() burried in the builtin operator module in case you really do care ;) ... operator.isSequenceType() operator.isMappingType() + some other C style _Check() APIs These only look at the type slots though, so Python instances will appear to support everything but when used fail with an exception if they don't provide the proper __xxx__ hooks. -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4