Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88097

Re: Supply condition in function call

Date 2015-03-27 08:37 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: Supply condition in function call
References <mf0nhv$e9r$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.217.1427405859.10327.python-list@python.org> (permalink)

Show all headers | View raw


On 26Mar2015 11:37, Peter Otten <__peter__@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@zip.com.au>

Nothing is impossible for the man who doesn't have to do it.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-27 08:37 +1100

csiph-web