pre-PEP generic objects

Jp Calderone exarkun at divmod.com
Wed Dec 1 02:44:59 CET 2004


On Tue, 30 Nov 2004 17:52:33 -0500, =?iso-8859-1?Q?Fran=E7ois?= Pinard <pinard at iro.umontreal.ca> wrote:
>[Scott David Daniels]
> 
> > You can simplify this:
> > class Hash(object):
> >     def __init__(self, **kwargs):
> >         for key,value in kwargs.items():
> >             setattr(self, key, value)
> 
> Might it be:
> 
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
> 

  One thing I notice with both of these versions:

    >>> Hash(self=10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: __init__() got multiple values for keyword argument 'self'

  __self would be better; a version that doesn't preclude the use of any key would be best.

  Jp



More information about the Python-list mailing list