Why is consistency so difficult to achieve?

  1 Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)
  2 [GCC 4.3.2] on linux2
  3 Type "help", "copyright", "credits" or "license" for more information.
  4 
  5  >>> def f(*args):
  6  ...   print ' '.join([str(a) for a in args])
  7 ...
  8  >>> f(1,2,3)
  9 1 2 3
 10  >>> f(1,*(2,3))
 11 1 2 3
 12  >>> f(*(1,2),3)
 13   File "<stdin>", line 1
 14     f(*(1,2),3)
 15              ^
 16 SyntaxError: invalid syntax

Sigh.

About these ads

7 thoughts on “Why is consistency so difficult to achieve?

  1. No use sighing. The asterisk form has a specific meaning, and is specifically required to be the last argument. It isn’t Python’s fault that tou won’t read, or won’t follow, the documentation.

  2. Steve > Python 3 allow this kind of syntax, and python has been realased this days, so perhaps this post have a relation with it and our friend use sighing because he can’t wait to use it…

  3. Pingback: This *is* much better indeed :) « Muharem Hrnjadovic

  4. “Python 3 allow this kind of syntax”

    Well, no, but it does allow f(*(1,2), c=3) and it has a better error message.

    The Python2 solution is of course to either expand the tuple:

    t = (1,2)
    f(t[0], t[1], 3)

    Or add the third parameter to the tuple:

    f(*(1,2)+(3,))

  5. Although he could be nicer about it, Steve’s right. The (a, b, c, *args, **kwargs) pattern is both well-documented and well known. And, incidentally, someone matching the Python idea that there should be only one way to do it.

  6. @ Steve and J.T.

    It’s well documented indeed. But you have to admit that in Python 3 it’s *even better* documented. Documentation is not religion :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s