A small inconsistency in syntax?

Brian Quinlan BrianQ at ActiveState.com
Mon Oct 29 16:34:32 EST 2001


James wrote:
> Brian Quinlan wrote:
> >I could want to write:
> >a = ['x value','y value','z value'] = x
> >
> >Here the intermediate list is doing 3 things for me:
> >
> >1. it's providing documentation
> >2. it's forcing the sequence type to be of length 3
> >3. it's making the type assigned to 'a' a list
>
> and
>
> 4. it's providing a handy way to generate a syntax error ;-)
>
> Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit
> (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> >>>
> >>> a = ['x value','y value','z value'] = 1,2,3
> SyntaxError: can't assign to literal
> >>>

That was exactly the point of the original argument - that it is
reasonable to do sequence unpacking into mutable literals even though
the language does not allow it.

Cheers,
Brian





More information about the Python-list mailing list