<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Implicit Python Properties</title>
	<link>http://lucumr.pocoo.org/cogitations/2007/06/03/implicit-python-properties/</link>
	<description>Armin Ronacher thinking</description>
	<pubDate>Thu, 28 Aug 2008 02:53:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>

	<item>
		<title>By: koder</title>
		<link>http://lucumr.pocoo.org/cogitations/2007/06/03/implicit-python-properties/#comment-5</link>
		<author>koder</author>
		<pubDate>Mon, 11 Jun 2007 13:01:31 +0000</pubDate>
		<guid>http://lucumr.pocoo.org/cogitations/2007/06/03/implicit-python-properties/#comment-5</guid>
		<description>Interesting  post. I use other code, but it don't work with lambda's :

&lt;pre&gt;def mkprop(func):
    gfunc = sfunc = dfunc = None
    for i in func.func_code.co_consts:
        if isinstance(i,types.CodeType):
            if i.co_name == 'get':
                gfunc = new.function(i,globals())
            elif i.co_name == 'set':
                sfunc = new.function(i,globals())
            elif i.co_name == 'set':
                sfunc = new.function(i,globals())
    if not gfunc and not sfunc and not dfunc:
        raise ValueError("Can't found and function to make property")
    else:
        return property(fget = gfunc,fset = sfunc,
                        fdel = dfunc,doc = func.__doc__)
class Test(object):
    @mkprop
    def prop():
        "property"
        def set(self,val):
            self._val = val
        def get(self):
            return self._val
    #but not like this
    #def prop():
    #    get = lambda self : self._val
    #    set = my_other_function&lt;/pre&gt;

&#62; It’s cool to see what’s possible with python, even if it makes no sense and nobody would  
&#62; ever use it :D

I'm gonna use it, instead o my one's ;).
P.S. +1 on Python cool.</description>
		<content:encoded><![CDATA[<p>Interesting  post. I use other code, but it don&#8217;t work with lambda&#8217;s :</p>
<pre>def mkprop(func):
    gfunc = sfunc = dfunc = None
    for i in func.func_code.co_consts:
        if isinstance(i,types.CodeType):
            if i.co_name == 'get':
                gfunc = new.function(i,globals())
            elif i.co_name == 'set':
                sfunc = new.function(i,globals())
            elif i.co_name == 'set':
                sfunc = new.function(i,globals())
    if not gfunc and not sfunc and not dfunc:
        raise ValueError("Can't found and function to make property")
    else:
        return property(fget = gfunc,fset = sfunc,
                        fdel = dfunc,doc = func.__doc__)
class Test(object):
    @mkprop
    def prop():
        "property"
        def set(self,val):
            self._val = val
        def get(self):
            return self._val
    #but not like this
    #def prop():
    #    get = lambda self : self._val
    #    set = my_other_function</pre>
<p>&gt; It’s cool to see what’s possible with python, even if it makes no sense and nobody would<br />
&gt; ever use it :D</p>
<p>I&#8217;m gonna use it, instead o my one&#8217;s ;).<br />
P.S. +1 on Python cool.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
