Reinhold Birkenfeld wrote:
> Michele Simionato wrote:
>> As other explained, the syntax would not work for functions (and it is
>> not intended to).
>> A possible use case I had in mind is to define inlined modules to be
>> used as bunches
>> of attributes. For instance, I could define a module as
>>
>> module m():
>> a = 1
>> b = 2
>>
>> where 'module' would be the following function:
>>
>> def module(name, args, dic):
>> mod = types.ModuleType(name, dic.get('__doc__'))
>> for k in dic: setattr(mod, k, dic[k])
>> return mod
>
> Wow. This looks like an almighty tool. We can have modules, interfaces,
> classes and properties all the like with this.
>
> Guess a PEP would be nice.
Very nice indeed. I'd be more supportive if it was defined as a new statement
such as "create" with the syntax:
create TYPE NAME(ARGS):
BLOCK
The result would be roughly equivalent to:
kwds = {}
exec BLOCK in kwds
NAME = TYPE(NAME, ARGS, kwds)
Such that the existing 'class' statement is equivalent to:
create __metaclass__ NAME(ARGS):
BLOCK
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com