[Python-ideas] Short form for keyword arguments and dicts

Ron Adam ron3200 at gmail.com
Wed Jun 26 17:13:10 CEST 2013



On 06/26/2013 09:46 AM, Joshua Landau wrote:
> However; maybe:
>
>      class AttrDict(dict):
>          def __init__(self, mapping, **defaults):
>              super().__init__(defaults, **mapping)
>              self.__dict__ = self
>
>      def __init__(self, **kwds):
>          kwds = AttrDict(kwds, text="Hello", font=system_font)
>
>          kwds.size = calc_default_size(kwds.text, kwds,font)
>
>          Widget.__init__(self, **kwds)
>
> and a decorator could even make this:
>
>      @dynamic_kwds(text="Hello", font=system_font)
>      def __init__(self, kwds):
>          kwds.size = calc_default_size(kwds.text, kwds,font)
>          Widget.__init__(self, **kwds)
>
> which would have the same run-time effect as the original (the second
> keeps re-evaluating the signature).
>
>
> Again; I mention these only to show people not to have a restricted
> idea on what the solution looks like - don't just try and fix the
> symptoms of the problem.

It's always good advise to keep an open mind.

I think the participants of this thread know they can use functions and 
decorators as helpers, but those always have some cost in processing time 
and memory usage.

It's much harder to find a clean solution that doesn't use those.

Cheers,
    Ron



More information about the Python-ideas mailing list