[Tutor] Question About Function Arguments and Returned Results
Kent Johnson
kent37 at tds.net
Wed Apr 12 04:32:35 CEST 2006
Richard Querin wrote:
>
>
> On 4/11/06, *Kent Johnson* <kent37 at tds.net <mailto:kent37 at tds.net>> wrote:
>
>
> There is no need to pass the class object in to the function, you can
> create it in the function and return it. A class might be nice because
> it gives names to the various values. A dict can also be used for this.
> Do what feels right :-)
>
>
> To be more specific, I'm going to have probably 6 functions that do
> similar things. They all take slightly different arguments, they all do
> slightly different calculations, but the results of all the functions
> are the same format. So I guess it makes sense to use a class. Now, when
Yes, that's a good argument for a class.
> you say 'create it in the function', you mean create the class instance
> inside the function and return that instance? The class itself is
> defined somewhere else in the module containing the functions so that
> all the functions have access to it. (Total newb to python and classes
> so sorry if that's a stupid question).
Right, create the class instance in the function.
class ReturnedValue(object):
def __init__(self, value):
self.value = value
def myFunction(x, y, z, w):
return ReturnedValue(x+y+z+w)
Season to taste ;)
Kent
More information about the Tutor
mailing list