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


Groups > comp.lang.python > #88097 > unrolled thread

Re: Supply condition in function call

Started byCameron Simpson <cs@zip.com.au>
First post2015-03-27 08:37 +1100
Last post2015-03-27 08:37 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#88097 — Re: Supply condition in function call

FromCameron Simpson <cs@zip.com.au>
Date2015-03-27 08:37 +1100
SubjectRe: Supply condition in function call
Message-ID<mailman.217.1427405859.10327.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web