#๐ in Python.... how to mimic C/++ struct?
12 messages ยท Page 1 of 1 (latest)
@restive bear
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
you most likely want dataclasses
Okay
And the normal class in python already is like a C++ struct because the only difference in C++ between struct and class is that the default Accessibility in a struct is public and in a class private and since python has no access modifiers, everything is public. But you can not declare members in python.
depends on what you need them for
If you don't care about static analysis, you can just use a dict
point = {"x": 1, "y": 5}
Why do you need to mimic a struct? Do you want it for the grouping in memory, or do you just want to associate different data with each other?
For the former, look into struct
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.