Is there a data type in Python similar to structs in C++?
问题 Is there a data type in Python similar to structs in C++? I like the struct feature myStruct.someName . I know that classes have this, but I don't want to write a class everytime I need a "container" for some data. 回答1: Why not? Classes are fine for that. If you want to save some memory, you might also want to use __slots__ so the objects don't have a __dict__ . See http://docs.python.org/reference/datamodel.html#slots for details and Usage of __slots__? for some useful information. For