> > def foo(): > a, b, c = 1, 2, 3 > function(a=77, **use('b d')) > > foo() > You get the output “77 None 33 None”. So basically it doesn’t work at all. > For the reason I wrote clearly in my last mail. You have to dig through the > stack frames to make use() work. >
OK, you are right. Improved implementation. Still not very hard. In any case, I'm concerned with the API to *use* the `use()` function, not how it's implemented. The point is really just that we can accomplish the same thing you want without syntax added. >>> import inspect >>> def reach(name): ... for f in inspect.stack(): ... if name in f[0].f_locals: ... return f[0].f_locals[name] ... return None ... >>> def use(names): ... kws = {} ... for name in names.split(): ... kws[name] = reach(name) ... return kws ... >>> def function(a=11, b=22, c=33, d=44): ... print(a, b, c, d) ... >>> function(a=77, **use('b d')) 77 None 33 None >>> def foo(): ... a, b, c = 1, 2, 3 ... function(a=77, **use('b d')) ... >>> foo() 77 2 33 None
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/