[Numpy-discussion] ndarray is not a sequence

Sturla Molden sturla.molden at gmail.com
Tue Mar 4 09:47:50 EST 2014


Chris Barker <chris.barker at noaa.gov> wrote:

> Sure -- but I'm afraid that there will be a lot of code that does an
> isinstance() check where it it absolutely unnecessary. If you really need
> to know if something is a sequence or a mapping, I suppose it's required,
> but how often is that?

I must say I don't understand the purpose of Java-like interfaces in
Python. It is better to ask forgiveness than ask permission. If an object
does not have the required attributes we sooner or later get an
AttributeError. Is doing an isinstance() check and then raising TypeError
inherently better? In both cases we get an error that unit tests should
detect. I might do sanity checks on the input data if it is required to
ensure correct output. But I never do this to ensure that objects have all
the attributes they should. If they don't I prefer my program to die with
an unhandled AttributeError.

Sturla




More information about the NumPy-Discussion mailing list