[Tutor] assigning __doc__ strings (manually)

Jeff Shannon jeff at ccvcorp.com
Thu Sep 2 21:18:13 CEST 2004


> At 02:35 PM 9/2/2004 +0100, Hans Fangohr wrote:
> 
>> The ideal syntax to call the integrater function RKF would be this:
>>
>> T,Y = RKF( g, t0=0, tfinal=10 )
>>
>> meaning that the function g(y,t) should be integrated from t=0 to t=10.
>>
>> If one wants to analyse the performance of the integration in more
>> detail, then I'd like to call the function like this:
>>
>> T,Y,log = RKF( g, t0=0, tfinal=10 )
>>
>> where log could be a dictionary containing all sorts of extra data, or
>> a list of arrays or something along those lines.

Depending on your particular usage, it may also be reasonable to 
simply always return the extra data, and leave it up to the calling 
code to either use it or discard it:

   T, Y = RKF( g, t0= 0, tfinal=10 )[:2]

     or

   T, Y, _ = RKF( g, t0= 0, tfinal=10 )

I'm thinking in particular of the standard library function 
os.path.splitext(), which splits a file extension from a path/file 
name.  It returns both the base name (without the extension) and the 
extension even though most of the time that this is used, the 
extension itself is all that's needed and the base name is just thrown 
away.

This does suffer from feeling a bit less "clean", since you're 
constantly throwing stuff away.  On the other hand, it spares you 
having two very-similar-purpose functions, and makes the act of 
discarding unneeded data more explicit.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Tutor mailing list