python equivalent of wantarray() : newbie

Moshe Zadka moshez at zadka.com
Wed Sep 12 07:37:16 EDT 2001


On Wed, 12 Sep 2001, Karthik Gurumurthy <karthikg at aztec.soft.net> wrote:

> perl can determine the type of the variable used
> 
> @array = call()//so it's list context so call can return a list
> $var = call()//scalar context so call can return say a string.
> 
> But can python determine the same?? i guess it can't and that's why we don't
> have a wantarray() equivalent
> in python??

Exactly.
In

a = call()

Would you want an array "context" or a scalar context? 
Just have different functions, as you should have done in Perl...
I've never seen a good excuse (even in Perl) to have context-dependant
functions, and the one time I was tempted to do it, it was a maintenance
nightmare.




More information about the Python-list mailing list