How to instantiate in a lazy way?

Slaunger Slaunger at
Tue Dec 2 21:45:13 CET 2008

On 2 Dec., 17:50, George Sakkis <george.sak... at> wrote:
> >                 I1, Q1, I2, Q2 = bytes_to_data(buf)
> >                 self.__dict__["I1"] = I1
> >                 self.__dict__["Q1"] = Q1
> >                 self.__dict__["I2"] = I2
> >                 self.__dict__["Q2"] = Q2
> with:
>     self.__dict__.update(zip(self.data_attr_names, bytes_to_data
> (buf)))
> where data_attr_names = ("I1", "Q1", "I2", "Q2") instead of a
> frozenset. A linear search in a size-4 tuple is unlikely to be the
> bottleneck with much I/O anyway.

Thank you for this little hint, George.
I've never used update on a dict and the zip function before.
This is a nice application of these functions.

And I agree, performance is not an issue by selecting a tuple instead
of a frozenset. The bytes_to_data function is the performance
in the actual application (implemented in parent class).

-- Slaunger

More information about the Python-list mailing list