[Python-ideas] Allow "assigning" to Ellipse to discard values.
Antoine Pitrou
solipsis at pitrou.net
Wed Feb 11 16:46:15 CET 2015
On Tue, 10 Feb 2015 13:23:58 -0800
Chris Barker <chris.barker at noaa.gov> wrote:
> On Tue, Feb 10, 2015 at 1:01 PM, Spencer Brown <spencerb21 at live.com> wrote:
>
> > Basically, in any location where a variable name is provided for
> > assignment (tuple unpacking, for loops, function parameters, etc) a
> > variable name can be replaced by '...' to indicate that that value will not
> > be used. This would be syntactically equivalent to del-ing the variable
> > immediately after, except that the assignment never needs to be done.
> >
> > Examples:
> > >>> tup = ('val1', 'val2', (123, 456, 789))
> > >>> name, ..., (..., value, ...) = tup
> >
>
> I generally handle this by using a really simple no-meaning name, like"_" :
>
> name, _, (_, value, __ ) = tup
>
> granted, the _ sticks around and keeps the object alive, which may cause
> issues. But is it often a big deal?
The actual deal with that is when you are using gettext or a
similar I18N framework :-)
Regards
Antoine.
More information about the Python-ideas
mailing list