[Python-ideas] Quick idea: defining variables from functions that take the variable name

Steven D'Aprano steve at pearwood.info
Wed Jun 1 13:26:23 EDT 2016


On Wed, Jun 01, 2016 at 04:54:22PM +0000, Michael Selik wrote:
> On Wed, Jun 1, 2016 at 12:33 PM Paul Moore <p.f.moore at gmail.com> wrote:

> > There's almost no room for improvement in those two use cases, and yet
> > people still like the idea of "not repeating the name".
> >
> 
> And some people don't!
[...]
> In fact, I often use namedtuple with a dynamic __name__ and fields, without
> changing the identifier.
> 
>     Record = namedtuple(name, fields)
> 
> If I use that in half my code, but then in the other half, something like
> 
>     Record => namedtuple(fields)
> 
> That's TIMTOWTDI. I'd rather standardize.

That's fine. Nobody is going to force you to change.

I'm not proposing any changes to namedtuple at all -- its others who 
want to change it to take just a single argument and have an wrapper 
function to specify the field names. I'm against that rather strongly.


[...]
> I haven't seen an explanation of how this proposal would simplify
> Django.

I fear I may have been mislead by Sven, who made comments about this 
being useful for Django, but hasn't given any examples yet.


-- 
Steve


More information about the Python-ideas mailing list