<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Small Python Interactive Interface Trick</title>
	<atom:link href="http://www.algorithm.co.il/blogs/programming/python/small-python-interactive-interface-trick/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/</link>
	<description>Algorithms, for the heck of it</description>
	<lastBuildDate>Tue, 21 Jun 2011 21:07:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: hmarr</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-151</link>
		<dc:creator>hmarr</dc:creator>
		<pubDate>Mon, 01 Dec 2008 18:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-151</guid>
		<description>lorg:
Of course! Clearly I didn&#039;t have my head screwed on properly when I wrote that!</description>
		<content:encoded><![CDATA[<p>lorg:<br />
Of course! Clearly I didn&#8217;t have my head screwed on properly when I wrote that!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-150</link>
		<dc:creator>lorg</dc:creator>
		<pubDate>Mon, 01 Dec 2008 09:45:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-150</guid>
		<description>llr:
No, it isn&#039;t.
In your code snippet, t holds the result of a single call to test().
However, in the interactive prompt when you do
&gt;&gt;&gt; x [enter]
x.__repr__() gets called.
So, in my version, each time you try to view t, you actually call NoParens.__repr__, and that means a new call to test. I believe this would be clearer if test() returned time.time():

[python]
In [2]: import noparens

In [3]: import time

In [4]: def test():
   ...:     return time.time()
   ...:

In [5]: t = noparens.NoParens(test)

In [6]: t
Out[6]: 1228124415.74

In [7]: t
Out[7]: 1228124416.37
[/python]</description>
		<content:encoded><![CDATA[<p>llr:<br />
No, it isn&#8217;t.<br />
In your code snippet, t holds the result of a single call to test().<br />
However, in the interactive prompt when you do<br />
>>> x [enter]<br />
x.__repr__() gets called.<br />
So, in my version, each time you try to view t, you actually call NoParens.__repr__, and that means a new call to test. I believe this would be clearer if test() returned time.time():</p>
<p>[python]<br />
In [2]: import noparens</p>
<p>In [3]: import time</p>
<p>In [4]: def test():<br />
   &#8230;:     return time.time()<br />
   &#8230;:</p>
<p>In [5]: t = noparens.NoParens(test)</p>
<p>In [6]: t<br />
Out[6]: 1228124415.74</p>
<p>In [7]: t<br />
Out[7]: 1228124416.37<br />
[/python]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: llr</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-149</link>
		<dc:creator>llr</dc:creator>
		<pubDate>Mon, 01 Dec 2008 08:44:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-149</guid>
		<description>Is this your script&#039; purpose as I think? like below:

&gt;&gt;&gt; def test():
...     return 4**4
...
&gt;&gt;&gt; t = test()
&gt;&gt;&gt; t
256
&gt;&gt;&gt;</description>
		<content:encoded><![CDATA[<p>Is this your script&#8217; purpose as I think? like below:</p>
<p>&gt;&gt;&gt; def test():<br />
&#8230;     return 4**4<br />
&#8230;<br />
&gt;&gt;&gt; t = test()<br />
&gt;&gt;&gt; t<br />
256<br />
&gt;&gt;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-148</link>
		<dc:creator>lorg</dc:creator>
		<pubDate>Mon, 01 Dec 2008 07:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-148</guid>
		<description>hmarr:
Nice idea!
However, to do what you propose you don&#039;t need to change the code of NoParens, you can already use it as is. Any callable object may be used as a decorator.</description>
		<content:encoded><![CDATA[<p>hmarr:<br />
Nice idea!<br />
However, to do what you propose you don&#8217;t need to change the code of NoParens, you can already use it as is. Any callable object may be used as a decorator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hmarr</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-147</link>
		<dc:creator>hmarr</dc:creator>
		<pubDate>Mon, 01 Dec 2008 02:13:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-147</guid>
		<description>Could work nicely as a decorator too:

def noparens(func):
    class ReprFunc(object):
        def __init__(self, f):
            self.f = f
        def __repr__(self):
            return str(self.f())
        def __call__(self, *args, **kwargs):
            return self.f(*args, **kwargs)
    return ReprFunc(func)

Usage:

@noparens
def foo():
    return 6*3

&gt;&gt;&gt; foo
18</description>
		<content:encoded><![CDATA[<p>Could work nicely as a decorator too:</p>
<p>def noparens(func):<br />
    class ReprFunc(object):<br />
        def __init__(self, f):<br />
            self.f = f<br />
        def __repr__(self):<br />
            return str(self.f())<br />
        def __call__(self, *args, **kwargs):<br />
            return self.f(*args, **kwargs)<br />
    return ReprFunc(func)</p>
<p>Usage:</p>
<p>@noparens<br />
def foo():<br />
    return 6*3</p>
<p>&gt;&gt;&gt; foo<br />
18</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-146</link>
		<dc:creator>lorg</dc:creator>
		<pubDate>Sun, 30 Nov 2008 23:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-146</guid>
		<description>Knorby:
Two reasons:
1. I didn&#039;t know about it, thanks :)
2. Even if I had, I couldn&#039;t have used it. I was using an embedded Python shell, that doesn&#039;t work with IPython. Although integrating it is possible, that work wasn&#039;t done.
That made using this shell even more painful, because I didn&#039;t have all the fancy IPython features, such as tab-completion. That pain made this trick even more useful than it normally is.</description>
		<content:encoded><![CDATA[<p>Knorby:<br />
Two reasons:<br />
1. I didn&#8217;t know about it, thanks :)<br />
2. Even if I had, I couldn&#8217;t have used it. I was using an embedded Python shell, that doesn&#8217;t work with IPython. Although integrating it is possible, that work wasn&#8217;t done.<br />
That made using this shell even more painful, because I didn&#8217;t have all the fancy IPython features, such as tab-completion. That pain made this trick even more useful than it normally is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: knorby</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-145</link>
		<dc:creator>knorby</dc:creator>
		<pubDate>Sun, 30 Nov 2008 20:03:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-145</guid>
		<description>Why not just use %autocall from the &lt;a href=&quot;http://ipython.scipy.org/doc/manual/html/interactive/reference.html#magic-commands&quot; rel=&quot;nofollow&quot;&gt;IPython magic commands&lt;/a&gt;? You wouldn&#039;t be able to do everything that you can do with your trick (just calling &quot;t&quot; would work the same, but not &quot;t,t,t&quot;), but it would require a whole lot less effort.</description>
		<content:encoded><![CDATA[<p>Why not just use %autocall from the <a href="http://ipython.scipy.org/doc/manual/html/interactive/reference.html#magic-commands" rel="nofollow">IPython magic commands</a>? You wouldn&#8217;t be able to do everything that you can do with your trick (just calling &#8220;t&#8221; would work the same, but not &#8220;t,t,t&#8221;), but it would require a whole lot less effort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-144</link>
		<dc:creator>lorg</dc:creator>
		<pubDate>Sun, 30 Nov 2008 14:56:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-144</guid>
		<description>Thanks :)
The best example would be a debugger:
Given a single_step() function, use s as a shorthand, and maybe r for run(), and p for print_state().
Given these, debugging with a Python interactive prompt gets a little bit easier. Especially when you can do:
s,s,s,p,r</description>
		<content:encoded><![CDATA[<p>Thanks :)<br />
The best example would be a debugger:<br />
Given a single_step() function, use s as a shorthand, and maybe r for run(), and p for print_state().<br />
Given these, debugging with a Python interactive prompt gets a little bit easier. Especially when you can do:<br />
s,s,s,p,r</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arkon</title>
		<link>http://www.algorithm.co.il/blogs/programming/small-python-interactive-interface-trick/#comment-143</link>
		<dc:creator>arkon</dc:creator>
		<pubDate>Sun, 30 Nov 2008 11:26:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=116#comment-143</guid>
		<description>hey man
glad you are back to write posts :)
can you give a more practical example maybe?</description>
		<content:encoded><![CDATA[<p>hey man<br />
glad you are back to write posts :)<br />
can you give a more practical example maybe?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

