[Python-ideas] Treat underscores specially in argument lists (original) (raw)

Giampaolo Rodola' g.rodola at gmail.com
Tue Feb 17 13:57:20 CET 2015


On Tue, Feb 17, 2015 at 5:24 AM, Andrew Barnert < abarnert at yahoo.com.dmarc.invalid> wrote:

On Feb 16, 2015, at 18:45, Ryan Gonzalez <rymg19 at gmail.com> wrote:

It's usually in callbacks where you only care about a few arguments.

A perfect example is using Tk variable tracing in tkinter (for validation or post-change triggering on widgets). The signature of the trace callback is callback(name, index, mode). You almost never need the index, you rarely need the mode, so you write: def callback(self, name, , mode): In fact, you usually don't need the mode either (in fact, you often don't even need the name), but you can't write this: def callback(self, name, , ): So instead you usually write something like: def callback(self, name, *): Personally, I find * ugly, so I use *dummy instead. But whatever. So anyway, what if you needed the index, but not the name or mode? You can't use * to get around that; you have to come up with two dummy names. That's a bit annoying. The question is, how often do you really need to ignore multiple parameters, but not all of them (or all of them from this point on)? I can't remember any callback API that I've used where that came up

Me neither. I remember doing this:

a, _, _, _, b, c = foo

...but never wanting to do a similar thing applied to a function signature. A function strikes me as something "more important" than "a, _, _, _, b, c = foo" appearing in the middle of the code, something which mandates explicitness, even when some args are ignored, in fact I don't remember ever seeing "def callback(self, name, _)". -1

-- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150217/05d96678/attachment.html>



More information about the Python-ideas mailing list