See exactly what a function has returned

Jeff Shannon jeff at
Wed Sep 15 22:00:47 CEST 2004

Brad Tilley wrote:

> def print_whats_returned(function):
>     ## A function that shows what another function has returned
>     ## as well as the 'type' of the returned data.
>     print function
>     print type(function)
> def send_net_params_to_admin(ip_param, port_param):
>     ip = get_server_ip()
>     port = get_server_port()
>     return ip, port
> print_whats_returned(send_net_params_to_admin(get_server_ip(), 
> get_server_port()))

Note here that the argument to print_whats_returned() is *not* a 
function; it is the value returned from a function.  You're not passing 
the function send_net_params_to_admin();  you're passing whatever is 
returned from it.  It is effectively equivalent to the following:

    return_value = send_net_params_to_admin(get_server_ip(), 

Thus, your function would be much more clear with different names, since 
it really has nothing to do with functions.

    def print_value_and_type(value):
        print value
        print type(value)

With these names, you wouldn't have had all of these people talking 
about dynamic typing and such, because it would've been clear that 
you're not attempting to find the intended return value of a theoretical 
future function call, but rather trying to inspect the actual value 
that's already been returned by a previously-executed function call. 

And no, there isn't really an easier way to do this.  :)

Jeff Shannon
Credit International

More information about the Python-list mailing list