A small inconsistency in syntax?

Michael Abbott michael at rcp.co.uk
Thu Oct 25 15:47:23 CEST 2001


It seems to me that there's a little inconsistency in assigning to tuples:

    	>>> (x,) = ()
    	Traceback (most recent call last):
    	  File "<stdin>", line 1, in ?
    	ValueError: unpack tuple of wrong size

Yes, that's what I expect.

    	>>> () = ()
    	SyntaxError: can't assign to ()

Eh?  Why not?  It's just a matter of checking that the right hand side 
really is an empty tuple...

I actually hit this in some code, where I wrote:

    	time, status, () = myobject.read()

where I happen to know that that in this particular case my object will 
return an empty tuple in its third argument.

Ok, so it's easy enough for me to write

    	time, status, _ = myobject.read()

instead, so I'm grumbling about trivia here.



More information about the Python-list mailing list