Guido van Rossum <guido@python.org> writes: > > As a last remark (although this is too long already), > > I'd also like to extend the __slots__ syntax by the > > ability to express "embedded types", like the types > > supported by array. This again saves a lot of memory > > when you know your attribute is always some simple type, > > which need not become an object. > > Can you suggest a concrete syntax to do this? Maybe setting __slots__ > to a dictionary mapping names to type specifiers would do it -- and it > would even be backwards compatible: currently, if __slots__ is a dict, > its keys are used as slot names and its values are ignored, by virtue > of the way the type constructor iterates over __slots__. May I suggest to use an ordered sequence (of pairs) instead of a dict for __slots__. Then you also can completely control the layout that C code sees and construct C compatible structures or other data types from pure Python code. <plug> Here's how ctypes does it: It's named _fields_ instead of __slots__, and typically you write something like this class Point(Structure): _fields_ = [("x", "i"), ("y", "i")] which defines a Python objects having x and y instance vars, which must be integers. ctypes extends this so that instead of the (struct module compatible) format specified "i", also Python objects are allowed which describe a C data type. Thomas
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