Would Anonymous Functions Help in Learning Programming/Python?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Sep 24 05:43:59 EDT 2007


Cristian a écrit :
> On Sep 21, 5:21 pm, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
> 
>> Ok, then what about classes ? They also are objects-like-any-other,
>> after all. So should we have this syntax too ?
>>
>> MyClass = class(ParentClass):
>>    __init__ = function (self, name):
>>      self.name = name
>>
>> ?-)
> 
> For consistency I would suggest this, but Python already does this!
> 
> Foo = type('Foo', (object, ), {'bar': lambda self, bar: bar})
> 
> I've created a new class and then binded it to name afterwards. If you
> can import modules without special syntax and you can create classes
> without special syntax, why should functions be treated any
> differently?
> 

You already can create functions without using the def statement:

Help on class function in module __builtin__:

class function(object)
  |  function(code, globals[, name[, argdefs[, closure]]])
  |
  |  Create a function object from a code object and a dictionary.
  |  The optional name string overrides the name from the code object.
  |  The optional argdefs tuple specifies the default argument values.
  |  The optional closure tuple supplies the bindings for free variables.
  |


HTH



More information about the Python-list mailing list