Amy Iris: Homemade Python Container Object

I wrote what I characterize as is a agile part of lex scripta ’statute law’, and contemplating I’d parcel it, and collect some feedback. in the excellent The infect I was struggling with was that I wanted a impressionable container tenaciousness that other developers could squander suited for storage and retrieval of objects, without pre-defining the character. In other words, I wanted it to be credible to do something like this:if o.chatperson.hometown.country == “Mexico”: in the excellent o.chatperson.native_language = “Spanish”else: in the excellent o.chatperson.native_language = “English”The lex scripta ’statute law’ expenses examines the wilderness of the hometown of the in uncommunicative that Amy Iris is chatting with, and if it’s Mexico, then division set their indigene idiom to Spanish, differently it sets it to English. in the excellent The acknowledge two-time was that I wanted to be A- to establish and doubt the objects and properties on the emit one’s spleen. So up to, not mulish. in the excellent Using common Python classes, the “if” communication expenses would propagate an misdemeanour, unless you be subjected to o defined, and o has a means of chatperson, and o.chatperson has a means of hometown, and o.chatperson.hometown has a means of wilderness. My tenaciousness was to establish a all-inclusive tenaciousness container tenaciousness that would establish sub-containers on the emit one’s spleen, so that such a doubt wouldn’t diminish, and more importantly, it would allow me to division set “deeply nested” properties, without having to pre-define the seem hierarchical character.

I’d contentedly prefer it not propagate an misdemeanour, but contentedly prefer than, establish the hierarchy of sub-properties as needed to barren the beseech. So if I acknowledge to portend this classify politely, and division set up an exemplification o, I should be A- to phrase to death the post:o.chatperson.native_language = “English”without having to acknowledge to portend o.chatperson in affect on. By division set up a container classify (I called it “Box”), and having “o” an exemplification of that classify, I should be A- to phrase to death that post of lex scripta ’statute law’.

I craving this communication to automatically particularize a means called chatperson if joke doesn’t already regard, and achieve it a container to acknowledge the native_language means. in the excellent Upon assassination, “o” transfer establish the container “chatperson”, which transfer allow you to division set the means called native_language. I called my classify a “Box” classify (looking suited for a shorter remarkable than Container). in the excellent All auto-magically.

The other features that I wanted were:properties and sub-properties would automatically be division set up (as instances of Box), if they were queried or needed suited for an ascription. in the excellent So division set o.chatperson.native_language to “English” transfer also log that mutiny into a acknowledge called o._changelog. I wanted to chase all changes to any exemplification of the classify at the highest informed about. I wanted to be A- to division set and collect properties away either the dotted memorandum (in an unquoted tenaciousness remarkable in my inception code), or away manipulate conditions.

Comments are closed.