__init__ as a lambda

Carl Banks pavlovevidence at gmail.com
Thu Aug 5 01:03:11 CEST 2010


On Aug 4, 12:58 pm, "Eric J. Van der Velden"
<ericjvandervel... at gmail.com> wrote:
> Hello,
>
> Suppose
>
> class C:
>  def __init__(self,name):self.name=name
>
> I was wondering if I could make the __init__ a lambda function, but
>
> class C:
>  __init__=lambda self,self.name:None
>
> and then later,
>
> C('Hello')
>
> does not work; the first argument, self, is assigned all rigth, but
> you cannot write the second argument with a dot,  self.name .
> Or can I somehow?


__init__=lambda self,name:setattr(self,'name',name)

However if you actually do this, you need to be smacked upside the
head.


Carl Banks



More information about the Python-list mailing list