Re: [Python-ideas] Syntax for making stuct / record / namedtuples

wxyarv wrote:
Right. I probably didn't express myself too well. The current recipe for 'structs' is here http://docs.python.org/tutorial/classes.html#odds-and-ends make an empty class, and assign fields as necessary. I prefer using factory functions, since I then I can define in a single place, what the 'struct' is supposed to contain, and the function signature will conveniently raise errors if I've made changes in module B, but not A. The same boilerplate code is also in all normal class init methods, you list the stuff once in the __init__ method arguments, then you list them again when you assign them, and I'm just wondering why do I have to repeat myself. As for named tuples, I quote http://docs.python.org/library/collections.html#namedtuple-factory-function-... "Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples." -- Eero Nevalainen

wxyarv wrote:
Right. I probably didn't express myself too well. The current recipe for 'structs' is here http://docs.python.org/tutorial/classes.html#odds-and-ends make an empty class, and assign fields as necessary. I prefer using factory functions, since I then I can define in a single place, what the 'struct' is supposed to contain, and the function signature will conveniently raise errors if I've made changes in module B, but not A. The same boilerplate code is also in all normal class init methods, you list the stuff once in the __init__ method arguments, then you list them again when you assign them, and I'm just wondering why do I have to repeat myself. As for named tuples, I quote http://docs.python.org/library/collections.html#namedtuple-factory-function-... "Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples." -- Eero Nevalainen
participants (2)
-
Eero Nevalainen
-
wxyarv