[Tutor] Subclassing list
bob gailer
bgailer at gmail.com
Thu Jun 18 17:56:00 CEST 2009
Luis N wrote:
> I get an error "TypeError: 'rounding' is an invalid keyword argument
> for this function" on my list subclass.
>
> How might I subclass list without this error?
>
> This is the code:
>
> class SeriesList(list):
> def __new__(cls, *args, **kwargs):
> series_list = list.__new__(cls, *args)
> series_list.rounding = kwargs.get('rounding', None)
> return series_list
>
> def moving_average(self, function, period=10):
> index = 0
> window = []
> ma = []
> for i in self.__iter__():
> i = float(i)
> if is_not_nan(i):
> window.insert(0, i)
> if len(window) == period:
> ma.append(function(window))
> window.pop()
> else:
> ma.append(float('nan'))
> return round(ma, self.rounding)
> ---
>
I copied and ran the above. It gives me no errors.
Of course all it is is a class definition.
Is there more to the code?
And please post the traceback so we have more information!
--
Bob Gailer
Chapel Hill NC
919-636-4239
More information about the Tutor
mailing list