Steven Bethard wrote:
> Rob Williscroft wrote:
>> I don't know wether this has been suggested or not, but what about def:
>>
>> def namespace ns:
>>   x = 1
>>
>> def type blah(object):
>>   pass
>>
>>   def property x:
>>     def get():
>>       return ns.x
> 
> I think that's probably a bad idea because it would make people think 
> that the statement acts like a function definition, when it actually 
> acts like a class definition.

maybe this could be marked with an appropriate decorator ?

@namespace(mytype)
def ns(base1,base2) :
     ...

the decorator could take the function object apart, recover the bases 
arguments, run the code with a referenced local dict...

hum, since in 2.4 exec allows a dict-like object as locals, it should 
even be possible to hack together a pretty concise hierarchical xml 
builder syntax embedded in current python - using neither the 'with' nor 
the 'make' statement, but simply defs !  Note that only the root of the 
(sub)tree  would need to be a decorated "def" since embedded defs could 
then be caught through the locals pseudo-dict.

Looks possible... at a first glance, the one thing that's unclear (to 
me) is how to deal with closure variables. To learn more, my tendency 
would be to launch a challenge :

"Simulate function call and execution using an exec statement, as 
precisely as possible"

I'll repeat that question in another thread...

Best, az.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to