[python-win32] return & tuples (& lists)

Tim Roberts timr at probo.com
Mon Jun 30 19:27:34 CEST 2008


Larry Bates wrote:
> Michel Claveau wrote:
>>
>> Not a question. Only a little note...  (for readers without Sunday 
>> activity)
>
> ...
> If you have a tuple and want to return it, just return it:  return vret
>
> If you want to wrap objects in a tuple to return it, I would recommend 
> using the build in tuple() command as the parenthesis can be 
> confusing:  return tuple(111,222,333).
>
> The reason return (vret,) works is because it is the same as: return 
> tuple(tuple(111,222,333) (the trailing comma is the key here and is 
> what tells python you mean a tuple instead of the "normal" parenthesis 
> meaning.
>
> May seem inconsistent, but I don't believe it really is.

Well, regardless of his typos, there is clearly at least ONE 
inconsistency here, in that returning a tuple behaves differently in the 
COM and non-COM cases.  Returning a scalar or a list works the same in 
both cases.

I don't know whether that's a well-documented side effect of some other 
process, or if it is a bug, but it is inconsistent.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list