News for hackers. Stuff that matters.
Re:Python's sad, unimaginative Enum by omaranto on Saturday May 11, 2013 @05:52PM (#5692234)

    class Color(Enum):
        red, green, blue, *_ = range(2**128)
        
        red_alias = red
Does that create a list of size 2^128-3 = 340282366920938463463374607431768211453 and assign it to Color._?
Re:Python's sad, unimaginative Enum by lclarkmichalek on Saturday May 11, 2013 @06:18PM (#5692316)
Ha! Too much Go for me. It does actually, my bad, I expected the variable to be ignored (and the range creation isn't a big deal usually as it's just a generator).
Re:Python's sad, unimaginative Enum by wasabian on Saturday May 11, 2013 @07:17PM (#5692491)
Using range would create the whole list. xrange is the one that acts like a generator :)
Re:Python's sad, unimaginative Enum by andreasvc on Saturday May 11, 2013 @07:28PM (#5692524)
This Enum is slated to be introduced in Python 3.4, where range is (not acts like) a generator.
Re:Python's sad, unimaginative Enum by wasabian on Saturday May 11, 2013 @07:36PM (#5692545)
Ah. I stand corrected :)
Re:Python's sad, unimaginative Enum by omaranto on Saturday May 11, 2013 @08:39PM (#5692675)
But even with a generator, as you would get from range in Python 3, the assignment

    a, *b = range(10)
makes b into a list. (And I think the star syntax in assignments is only Python 3, as far as I remember Python 2 only has star in argument lists of functions.)
Re:Python's sad, unimaginative Enum by __del__ on Sunday May 12, 2013 @05:10AM (#5693682)
You're right, python2 doesn't have the extended unpacking (star) syntax. Furthermore, this:

    >>> a, *b = range(2**128)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OverflowError: Python int too large to convert to C ssize_t
Ha.
Re:Python's sad, unimaginative Enum by andreasvc on Saturday May 11, 2013 @07:34PM (#5692538)
Yes it does and that is because it actually assigns all of the rest to a variable named '_'. The use of the underscore as a throwaway variable is just a convention and the interpreter is not aware that the result should be ignored.
Re:Python's sad, unimaginative Enum by jspiros on Saturday May 11, 2013 @06:09PM (#5692294)
Looks like it.