• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • The 'expand this here' * operator in python

    September 29th, 2009
    programming, python  [html]
    The python docs (2.6.2) say this about the use of *:
    5.3.4:

    If the syntax *expression appears in the function call, expression must evaluate to a sequence. Elements from this sequence are treated as if they were additional positional arguments; if there are positional arguments x1,..., xN, and expression evaluates to a sequence y1, ..., yM, this is equivalent to a call with M+N positional arguments x1, ..., xN, y1, ..., yM

    7.6:

    If the * is present [in the function definition argument list], it is initialized to a tuple receiving any excess positional parameters, defaulting to the empty tuple
    This is very handy, but is also limited. In python 3.0, PEP 3132 added some related syntax:
    first, *rest = seq
    a, *b, c = range(5)
    This is again, handy but limited. This star syntax only works in these two cases: functions (star-args) and assignment targets. There are logical extensions that make a lot of sense to me, though. If one can do:
    first, *rest = seq
    then I want to be able to do:
    seq = first, *rest
    While the following is ambiguous and so clearly needs to be illegal:
    first, *some, *rest = seq
    this is not ambiguous:
    seq = first, *some, *rest
    While we're at it, lets make the following legal:
    foo(first, *some, *rest)
    All these changes together would make for a very consistent and powerful interpretation of * as 'expand this sequence here'.

    Update 2013-04-05: Danner points out a 2008 patch. This was put on hold because of the moratotium (to "allow non-CPython implementations to 'catch up'") but with 3.3 out I think the moratorium is over. I just poked the bug.

    Recent posts on blogs I like:

    Who Should Bear the Risk in Infrastructure Projects?

    The answer to the question is the public sector, always. It’s okay to have private-sector involvement in construction, but the risk must be borne by the public sector, or else the private sector will just want more money to compensate for the extra risk. …

    via Pedestrian Observations November 30, 2020

    Fireside Friday, November 27, 2020

    Hey folks! Fireside this week. A bit of a change-up in terms of the coming attractions. I had planned to start “Textiles, How Did They Make It?” next, but I want to do a bit more reading on some of the initial stages of textile production (that is, the pr…

    via A Collection of Unmitigated Pedantry November 27, 2020

    Thoughts you mightn't have thunk about remote meetings

    Welcome to this week's edition of "building a startup in 2020," in which all your meetings are suddenly remote, and you probably weren't prepared for it. I know I wasn't. We started a "fully remote" company back in 2019, but …

    via apenwarr November 23, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact