Skip to main content
2 of 3
added 239 characters in body
dF.
  • 76.2k
  • 31
  • 136
  • 137

You can use a tuple for a lot of things where you would use a struct in C (something like x,y coordinates or RGB colors for example).

For everything else you can use dictionary, or a utility class like this one:

>>> class Bunch:
...     def __init__(self, **kwds):
...         self.__dict__.update(kwds)
...
>>> mystruct = Bunch(field1=value1, field2=value2)

I think the "definitive" discussion is here, in the published version of the Python Cookbook.

dF
  • 76.2k
  • 31
  • 136
  • 137