Re:Redesigning Python's named tuples
by joshuamorton on Friday September 01, 2017 @01:32AM
(#15146363)
>Python, however "struct" has a very different meaning in Python. sigh It's intended for encoding/decoding binary data from strings/bytes.
That's because the struct module is for dealing with structs, in the C/C++ sense. Like actual structs.
That aside, attrs is a great library!
A good link about metaclasses in Python:
https://stackoverflow.com/questions/100003/what-is-a-metacla...
I do like the concept of Structs. I first used them in Ruby, so I figured that all "very high" languages had the concept. Python, however "struct" has a very different meaning in Python. sigh It's intended for encoding/decoding binary data from strings/bytes.
https://docs.python.org/3.6/library/struct.html
There is a lesser known use case for the type(...) function. Normally, one would use it to find out an object's type.
But, it can also be used to create new class types. https://docs.python.org/3.6/library/functions.html#type Which is, essentially, what Ruby's Struct class provides. And, Python objects don't have privacy, so it's more comparable to the OpenStruct class.Edit: Just wanted to tack on a shout out to Attrs which is really nice improvement to "Struct" concept. http://www.attrs.org/en/stable/ h/t hynek