<br><br><div class="gmail_quote">On 16 March 2011 11:10, Larry Hastings <span dir="ltr"><<a href="mailto:larry@hastings.org">larry@hastings.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#ffffff"><div class="im">
<br>
On 03/16/2011 05:28 AM, Greg Ewing wrote:
<blockquote type="cite">If
I could write my overridable_property declarations
<br>
without having to repeat the name, this kind of thing would
<br>
not be able to happen.
<br>
</blockquote>
<br></div>
As I suggested in my email on the Assignment Decorators thread this
morning, you could achieve this in current Python, no extension
needed:<br>
<blockquote>def assign(fn):<br>
return fn(fn.__name__)<br>
<br>
@assign<br>
def content_size(name):<br>
return overridable_property(name,
"Size of the content area.")
</blockquote>
<br></div></blockquote><div><br></div><div><br></div><div>And building on this sightly you could do the following for namedtuple:</div><div><br></div><div><div>>>> from collections import namedtuple</div><div>
>>> import inspect</div><div>>>> def make_namedtuple(fn):</div><div>... args = ' '.join(inspect.getargspec(fn).args)</div><div>... return namedtuple(fn.__name__, args)</div><div>... </div>
<div>>>> @make_namedtuple</div><div>... def Point(x, y): pass</div><div>... </div><div>>>> p = Point(1, 2)</div><div>>>> p</div><div>Point(x=1, y=2)</div></div><div><br></div><div><br></div><div>
All the best,</div><div><br></div><div>Michael</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div text="#000000" bgcolor="#ffffff">
How bad do you want it? ;-)<br>
<br>
<br>
/larry/<br>
</div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><pre cols="72"><a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br><br>May you do good and not evil<br>May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>-- the sqlite blessing <a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a></pre>
<br>