[Ironpython-users] Calling len() on a DynamicObject instance?

Nicholas Devenish misnomer at gmail.com
Thu Oct 10 18:40:47 CEST 2013

On 10 Oct 2013, at 17:36, Jeff Hardy <jdhardy at gmail.com> wrote:

> I haven't looked at the implementation of len() yet, so I could be
> wrong, but my guess is that if your object doesn't implement IList (or
> something else with .Count) it will look for a __len__ method
> (http://bit.ly/16TDkIJ) on the object. This should be reified as a
> call to TryGetMember/TryInvoke, so you should be able to selectively
> provide __len__ for those objects that are collections and leave it
> out for those that are not.

In my tests, it wasn't trying to resolve __len__ on the dynamic object (I specifically tracked everything going through in case this was the solution). For now, I'll just return an IList-implementing separate DynamicObject subclass when appropriate.



More information about the Ironpython-users mailing list