C-like structures in Python

Update: Data Classes With the introduction of Data Classes in Python 3.7 we get very close. The following example is similar to the NamedTuple example below, but the resulting object is mutable and it allows for default values. This plays nicely with the new typing module in case you want to use more specific type annotations. I’ve been waiting desperately for this! If you ask … Read more

C-like structures in Python

Use a named tuple, which was added to the collections module in the standard library in Python 2.6. It’s also possible to use Raymond Hettinger’s named tuple recipe if you need to support Python 2.4. It’s nice for your basic example, but also covers a bunch of edge cases you might run into later as well. Your fragment above would … Read more