Re: use of dict() function
dn via Tutor <[email protected]> Mon, 3 Jun 2024 17:00:14 +1200
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Organization | DWM |
| Message-ID | <[email protected]> |
On 3/06/24 14:44, Alex Kleider wrote: > #!/usr/bin/env python3 > """ > Question: > I created a class which I initially coded as in Rec0. > I then read[1] that calling dict(mapping) returns a new dict > essentially providing the functionality of my class (except > for the call-ability feature.) > The interesting thing is that calling dict(mapping) within a class > definition seems to result in different behavior than when called > elsewhere. > Is there an explanation??? Take a look at type( d1 ) when returned by Rec0 and compare with Rec1. The problem is not so much the dict() call, but the process of combining two dictionaries (the incoming rec, and the class's self.__dict__). Try self.update( dict( rec ) ) for all your dreams to come True. The realise that the dict() is unnecessary. Why was it there in the first place? -- Regards, =dn _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor