See exactly what a function has returned
Brad Tilley
bradtilley at usa.net
Wed Sep 15 14:30:06 EDT 2004
Roy Smith wrote:
> In article <ci9tfk$71t$1 at solaris.cc.vt.edu>,
> Brad Tilley <bradtilley at usa.net> wrote:
>
>
>>Is there an easier way to do this:
>>
>>def print_whats_returned(function):
>> print function
>> print type(function)
>
>
> In the general case, this is not possible. A function can return
> different things at different times. Consider the following function:
>
> def getSomething ():
> if random.random () < 0.5:
> return 42
> else:
> return "fourty-two"
>
> so what type would you say this returns?
Depends on what randon.random came up with. Either way, we'd know what
the function returned and what type it was... and that's all I want to know.
More information about the Python-list
mailing list