On Thu, 26 Jun 2014 17:35:21 -0700 Benjamin Peterson email@example.com wrote:
On Thu, Jun 26, 2014, at 17:07, Paul Sokolovsky wrote:
With my MicroPython hat on, os.scandir() would make things only worse. With current interface, one can either have inefficient implementation (like CPython chose) or efficient implementation (like MicroPython chose) - all transparently. os.scandir() supposedly opens up efficient implementation for everyone, but at the price of bloating API and introducing heavy-weight objects to wrap info. PEP calls it "lightweight DirEntry objects", but that cannot be true, because all Python objects are heavy-weight, especially those which have methods.
Why do you think methods make an object more heavyweight?
Because you need to call them. And if the only thing they do is return object field, call overhead is rather noticeable.
namedtuples have methods.
Yes, unfortunately. But fortunately, named tuple is a subclass of tuple, so user caring for efficiency can just use numeric indexing which existed for os.stat values all the time, blissfully ignoring cruft which have been accumulating there since 1.5 times.