<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, May 24, 2018 at 8:00 AM Serhiy Storchaka <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">24.05.18 11:38, Neil Girdhar пише:<br>
> I was previously constructing an object like this:<br>
> <br>
> tb = TemporalBehavior(**kwargs, **parameters)<br>
> <br>
> where various subclasses were doing things like<br>
> <br>
> def __init__(self, some_kwarg, some_other_kwargs, some_parameter, <br>
> some_other_parameter):<br>
> <br>
> Then I realized that I want to pass the paramters as a dictionary so <br>
> that I can store it..  I changed the code to this:<br>
> <br>
> def __init__(self, some_kwarg, some_other_kwargs, parameters):<br>
> <br>
> but I still need "some_parameter", so I did<br>
> <br>
> some_parmeter = parameters['some_parameter']<br>
> some_other_parmeter = parameters['some_other_parameter']<br>
> <br>
> Great, but now I have to check that exactly the list of parameters that <br>
> I need is being sent in, so I need to do something like<br>
> <br>
> if set(parameters) != ('some_parameter', 'some_other_parameter'):<br>
>      raise ValueError<br>
> <br>
> It might be nice to do instead<br>
> <br>
> {'some_parameter': p, 'some_other_parameter': q} = parameters<br>
<br>
p = parameters.pop('some_parameter')<br>
q = parameters.pop('some_other_parameter')<br>
if parameters:<br>
     raise ValueError<br>
<br></blockquote><div>parameters is a Mapping subclass and I don't want to destroy it </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
or<br>
<br>
p, q = (lambda some_parameter, some_other_parameter: some_parameter, <br>
some_other_parameter)(**parameters)<br>
<br></blockquote><div>that works </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/rupoMkwAhi0/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/rupoMkwAhi0/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div></div>