Supply condition in function call
Cameron Simpson
cs at zip.com.au
Thu Mar 26 17:37:34 EDT 2015
On 26Mar2015 11:37, Peter Otten <__peter__ at web.de> wrote:
>You are right. [...]
>
>By the way, in this case you don't need the list at all:
>
>def vartuple(vars):
> return namedtuple("locals", vars)._make(vars.values())
Hmm. Neat. I had not realised that was available.
You'd need "vars.keys()", not "vars", for the first use of "vars", BTW:
return namedtuple("locals", vars.keys())._make(vars.values())
A remark for the OP: a method name like "_make" would normally be something you
would avoid as it is Python convenion that _* names are "private", which in
Python usually means subject to arbitrary change and probably not documented;
internal implementation mechanisms as opposed to published interfaces.
However, in namedtuple the word "_make" is chosen specificly to avoid clashes
with the "named" tuple values (which would normally not start with "_"), and it
is explicitly documented.
Thanks Peter!
Cheers,
Cameron Simpson <cs at zip.com.au>
Nothing is impossible for the man who doesn't have to do it.
More information about the Python-list
mailing list