See exactly what a function has returned
Brad Tilley
bradtilley at usa.net
Wed Sep 15 17:19:45 EDT 2004
Jeff Shannon wrote:
> 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(),
> get_server_port())
> print_whats_returned(return_value)
>
> 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
> Technician/Programmer
> Credit International
Thanks Jeff,
You said what I was trying to say better than I could say it. I'm not
crazy after all... just picked the wrong words. This made sense to me at
first, then everyone said, "You can't do that," and I was almost at the
point of believing them when you posted. ;)
Brad
More information about the Python-list
mailing list