[Tutor] use of dict() function
dn
PythonList at DancesWithMice.info
Mon Jun 3 01:00:14 EDT 2024
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
More information about the Tutor
mailing list