extend Python namedtuple with many @properties? -
How many nicknames can be extended with additional @products?
For some, any text can write down; But there are many, so I am looking for a generator or property factory. One way is to generate text from _fields
and exec exec; There will be one add_fields with the same effect on another runtime.
(My @props have to get rows and fields in the scattered database in several tables, so that rec.pname
is context [Rec.personid] .pname
; But there are other uses in nametuples-with-smart-fields.)
Expand to designate with multiple @ properties? "" ("Person", "PNN peder") # ... tolerant = [person ("Smith", "NY"), person ("Jones", "IL")] class top (nominated ("top_ "," Topping amount was in vain ")):" Property "- family - for the continuous [person] .pname - & gt; Individual pad ..." "" __ slots_ = () @ property DP person (self ): Return [self.personid] with the same effect as return # def add_fields (auto, Top.person, person._fields) Return? @ Property Def PNA (self): Return from self.person.pname @property def paddr (self): Return Self Posters. PDDR # ... too much REC = top (0, 42, 1) print rbc, rec .pname, rec.paddr
Answer to your question
How can the named nail be expanded or additional
@properties
?
can be sub-classified with: exactly the way you are doing this! What error are you getting? To see a simple case,
& gt; & Gt; & Gt; Square x (collections.nametuple ('y', 'a b c')): ... @property ... def D (self): return 23 ... & gt; & Gt; & Gt; A = x (1, 2, 3)> gt; & Gt; & Gt; AD D 23 & gt; & Gt; & Gt;
Comments
Post a Comment