On 21.04.2020 06:56, Chris Angelico wrote: > On Tue, Apr 21, 2020 at 9:27 AM M.-A. Lemburg <[email protected]> wrote: >> But arguing that f(a=, b=, c=, d=) is any better than >> f(a=a, b=b, c=c, d=d) does not really solve anything. >> >> The problem is with the code design, not with the syntax. >> >> You'd be better off putting your variables combined into a context >> object or container and pass that around: >> >> f(context) >> >> In many cases, you can avoid passing around any of these >> variables, by simply using an object rather than a function oriented >> approach. The variables would then become object attributes, >> so calling f() becomes: >> >> task.f() >> >> and the method f would get it's context straight from the >> object attributes of task -- without any arguments to pass in. > > Please explain how this will help the case of render_template and > similar, where the function accepts ANY keyword arguments, and then > passes them along to the template. Do I need to package everything up > into a dictionary? And how would that actually improve things, given > that I'd still need to do the exact same thing to construct that > dictionary? Every template has its own unique variables, and most of > them come straight from the calling function, with the same names. > > This is NOT going to be a consistent object with the same attributes. > That simply is not the use-case here. We already have that.
A render_template() function which has **kws as parameter can take any number of keyword parameters, including ones which are not used in the template. Those functions will usually take a namespace object as basis for rendering the final string. In the use case discussed here, that namespace would be locals(), so you could just as well write render_template(**locals()), or better: use a namespace object, fill this with the right values and pass in render_template(namespace). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 21 2020) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/WL5TVINJHC4ZG6RYKO7SFARAMVD62QNX/ Code of Conduct: http://python.org/psf/codeofconduct/
