Skip to content
Advertisement

Tag: python-internals

How can you slice with string keys instead of integers on a python OrderedDict?

Since an OrderedDict has the features of both a list (with ordered elements), and a dictionary (with keys instead of indexes), it would seem natural that you could slice using keys. What’s interesting about this is that it’s not the error you’d see due to OrderedDictionary.__getslice__ not being implemented. I tried adding my own __getslice__ method to OrderedDict, but I

Do attribute names consume memory on instance basis in python

Considering I have millions of objects with 3 __slots__ Is it more memory efficient to have short slot names like x vs. long like would_you_like_fries_with_that_cheeseburger? Or are the names allocated only once per class (opposed to once per instance?) Answer Names for slots only take memory per class, not per instance. Slots use descriptors that map directly into the memory

Advertisement