A small inconsistency in syntax?

James_Althoff at i2.com James_Althoff at i2.com
Mon Oct 29 17:27:21 EST 2001


Brian wrote:
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

Sorry ... didn't realize it had drifted into the realm of "what if things
were different" :-)

In which case, though, I suspect it would be more obvious to use "assert"
or test for "len" or use "list" or throw in a comment like
# ['x value','y value','z value']
-- rather than having to contemplate what [1,2,3] = 4,5,6 might mean and
how it might work and under what circumstances its usage would be
considered appropriate.  IMHO, Python already has too much special-case
stuff that one has to learn from folklore rather than being able to guess
or derive from a few simple, basic principles.

Jim






More information about the Python-list mailing list