Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    It kinda works but does not know how to print itself out myStruct Out[5]: __main__.myStruct Commented Dec 20, 2020 at 16:40
  • And why wouldn't you instantiate the class? What if one wants to use the same struct for different values? s1 = myStruct; s2 = myStruct; s1.field1 = "two" modifies s2. It depends on the use-case, but I think it's generally better/safer to actually instantiate the struct: s1 myStruct(); s2 = myStruct() Commented Dec 20, 2020 at 17:52
  • @StephenBoesch Yes, this is a very basic approach. I use this sometimes for ad-hoc scripts because it is simple to type, but for code which needs more functionality, I would use a more full-fledged solution like data classes. Commented Dec 26, 2020 at 13:45
  • @normanius Sure, if you need to copy your "structs", you need to be more clever and I agree that instantiating can create copies for you, if needed. Commented Dec 26, 2020 at 13:46