Timeline for answer to C-like structures in Python by Mark Biek
Current License: CC BY-SA 2.5
Post Revisions
3 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 9, 2018 at 17:16 | comment | added | Poikilos |
Same issue exists with PabloG's. Try adding the following code to his: pt3.w = 1 print pt3.w In a language with dicts, it is better to use them, especially for objects being serialized, since you can automatically use import json to save them and other serialization libraries as long as you don't have weird stuff inside of your dict. Dicts are the solution to keeping data and logic separate and are better than structs for people who don't want to write custom serialize and unserialize functions and don't want to use non-portable serializers like pickle.
|
|
| Feb 13, 2014 at 0:30 | comment | added | mobabo | This has been my approach as well, but I feel like it's dangerous precisely because a dictionary can accept anything for a key. There won't be an error if I set myStruct["ffield"] when I meant to set myStruct["field"]. The issue might (or might not) become apparent when I'm using or re-using myStruct["field"] later. I like PabloG's approach. | |
| Aug 30, 2008 at 14:35 | history | answered | Mark Biek | CC BY-SA 2.5 |