<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments for as i try to make my way</title>
	<link>http://www.zerbie.com</link>
	<description>crazy, some say</description>
	<pubDate>Thu, 28 Aug 2008 05:03:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>Comment on gimme that returned thing. by Lindsey</title>
		<link>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-31</link>
		<dc:creator>Lindsey</dc:creator>
		<pubDate>Tue, 20 May 2008 10:18:13 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-31</guid>
		<description>nat, the idea of such an operator sends a bit of chill down my spine.  The &lt;a href="http://books.google.com/books?id=ij8lVWNqgDoC&#38;pg=PA4&#38;lpg=PA4&#38;dq=%22consistent+renaming%22&#38;ots=4Mxwv0h_Cp&#38;sig=Fz51Ezj6aBUEHHlWdpNgno0kciE&#38;hl=en" rel="nofollow"&gt;consistent renaming&lt;/a&gt; problem is actually pretty hard even without this complication, and I think it would be really, really hard to implement it in a safe and predictable way.  What if the name collides with a name the next level up?  And so on.  

Also, Pam, my Python is awful, but how about just

&lt;code&gt;print do_something()&lt;/code&gt;

?  It seems to me that it's not so much about scope as it is that in the first example, the &lt;code&gt;do_something()&lt;/code&gt; function just never gets called.</description>
		<content:encoded><![CDATA[<p>nat, the idea of such an operator sends a bit of chill down my spine.  The <a href="http://books.google.com/books?id=ij8lVWNqgDoC&amp;pg=PA4&amp;lpg=PA4&amp;dq=%22consistent+renaming%22&amp;ots=4Mxwv0h_Cp&amp;sig=Fz51Ezj6aBUEHHlWdpNgno0kciE&amp;hl=en" rel="nofollow">consistent renaming</a> problem is actually pretty hard even without this complication, and I think it would be really, really hard to implement it in a safe and predictable way.  What if the name collides with a name the next level up?  And so on.  </p>
<p>Also, Pam, my Python is awful, but how about just</p>
<p><code>print do_something()</code></p>
<p>?  It seems to me that it&#8217;s not so much about scope as it is that in the first example, the <code>do_something()</code> function just never gets called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on a test suite for ice cream (1/?) by Terry</title>
		<link>http://www.zerbie.com/2008/04/04/a-test-suite-for-ice-cream-1/#comment-16</link>
		<dc:creator>Terry</dc:creator>
		<pubDate>Sun, 06 Apr 2008 01:25:54 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/04/a-test-suite-for-ice-cream-1/#comment-16</guid>
		<description>Most of the credit should really go to Jason Pellerin and Kumar McMillan, they're the idea guys. Me? I'm the guy behind the guy behind the guy (or gal, in Pam's case).</description>
		<content:encoded><![CDATA[<p>Most of the credit should really go to Jason Pellerin and Kumar McMillan, they&#8217;re the idea guys. Me? I&#8217;m the guy behind the guy behind the guy (or gal, in Pam&#8217;s case).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on generators != lists (?) by ars</title>
		<link>http://www.zerbie.com/2008/03/25/generators-lists/#comment-14</link>
		<dc:creator>ars</dc:creator>
		<pubDate>Sat, 05 Apr 2008 02:02:01 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/03/25/generators-lists/#comment-14</guid>
		<description>Generators are a nice and easy way to create iterators. Here's a silly example:

&lt;code&gt;
&#62;&#62;&#62; def gen():
...     yield 1
...     yield 2
...     yield 3
...
&#62;&#62;&#62; type(gen)

&#62;&#62;&#62; g = gen()
&#62;&#62;&#62; type(g)

&#62;&#62;&#62; g.next()
1
&#62;&#62;&#62; g.next()
2
&#62;&#62;&#62; g.next()
3
&#62;&#62;&#62; g.next()
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
&lt;/code&gt;

Basically, gen is just a function. It's the yield statements that let python know it's a generator. g is the actual generator object created from calling gen(). 

Calling g.next() the first time returns the first value that's "yielded". The second time, the function just picks up where it left off, so g.next() returns 2, etc. Until it drops off the end, at which point it raises a StopIteration exception. This is kind how iterators work behind the scenes. Generators make it easier to write iterators without defining a class and the next, iter methods. 

You don't usually use a generator in that way. Instead you would use it like an iterator, like this:

&lt;code&gt;
&#62;&#62;&#62; for num in gen():
...     print num
...
1
2
3
&lt;/code&gt;

Anyway, to your post ...  showlinks() returns a generator object, and you could call next() or just iterate through it with a for loop. 

When you create a list (links = list(showlinks())), it's basically iterated through the entire generator and stuffed the values in that list.

Each element of the list is actually a an instance of the Link class from the mechanize package (twill is using mechanize for its browsing facilities):

&lt;code&gt;
&#62;&#62;&#62; link = links[1]
&#62;&#62;&#62; link
Link(base_url='http://del.icio.us', url='https://secure.del.icio.us/login', text='login',
tag='a', attrs=[('href', 'https://secure.del.icio.us/login')])
&#62;&#62;&#62; type(link)

&#62;&#62;&#62; link.__class__

&#62;&#62;&#62; dir(link)
['__cmp__', '__doc__', '__init__', '__module__', '__repr__', 'absolute_url', 'attrs', 'bas
e_url', 'tag', 'text', 'url']
&#62;&#62;&#62; link.url
'https://secure.del.icio.us/login'
&#62;&#62;&#62; link.text
'login'
&#62;&#62;&#62; link.absolute_url
'https://secure.del.icio.us/login'
&#62;&#62;&#62; link.tag
'a'
&lt;/code&gt;

Hope that makes sense.</description>
		<content:encoded><![CDATA[<p>Generators are a nice and easy way to create iterators. Here&#8217;s a silly example:</p>
<p><code><br />
&gt;&gt;&gt; def gen():<br />
...     yield 1<br />
...     yield 2<br />
...     yield 3<br />
...<br />
&gt;&gt;&gt; type(gen)</p>
<p>&gt;&gt;&gt; g = gen()<br />
&gt;&gt;&gt; type(g)</p>
<p>&gt;&gt;&gt; g.next()<br />
1<br />
&gt;&gt;&gt; g.next()<br />
2<br />
&gt;&gt;&gt; g.next()<br />
3<br />
&gt;&gt;&gt; g.next()<br />
Traceback (most recent call last):<br />
  File "", line 1, in<br />
StopIteration<br />
</code></p>
<p>Basically, gen is just a function. It&#8217;s the yield statements that let python know it&#8217;s a generator. g is the actual generator object created from calling gen(). </p>
<p>Calling g.next() the first time returns the first value that&#8217;s &#8220;yielded&#8221;. The second time, the function just picks up where it left off, so g.next() returns 2, etc. Until it drops off the end, at which point it raises a StopIteration exception. This is kind how iterators work behind the scenes. Generators make it easier to write iterators without defining a class and the next, iter methods. </p>
<p>You don&#8217;t usually use a generator in that way. Instead you would use it like an iterator, like this:</p>
<p><code><br />
&gt;&gt;&gt; for num in gen():<br />
...     print num<br />
...<br />
1<br />
2<br />
3<br />
</code></p>
<p>Anyway, to your post &#8230;  showlinks() returns a generator object, and you could call next() or just iterate through it with a for loop. </p>
<p>When you create a list (links = list(showlinks())), it&#8217;s basically iterated through the entire generator and stuffed the values in that list.</p>
<p>Each element of the list is actually a an instance of the Link class from the mechanize package (twill is using mechanize for its browsing facilities):</p>
<p><code><br />
&gt;&gt;&gt; link = links[1]<br />
&gt;&gt;&gt; link<br />
Link(base_url='http://del.icio.us', url='https://secure.del.icio.us/login', text='login',<br />
tag='a', attrs=[('href', 'https://secure.del.icio.us/login')])<br />
&gt;&gt;&gt; type(link)</p>
<p>&gt;&gt;&gt; link.__class__</p>
<p>&gt;&gt;&gt; dir(link)<br />
['__cmp__', '__doc__', '__init__', '__module__', '__repr__', 'absolute_url', 'attrs', 'bas<br />
e_url', 'tag', 'text', 'url']<br />
&gt;&gt;&gt; link.url<br />
'https://secure.del.icio.us/login'<br />
&gt;&gt;&gt; link.text<br />
'login'<br />
&gt;&gt;&gt; link.absolute_url<br />
'https://secure.del.icio.us/login'<br />
&gt;&gt;&gt; link.tag<br />
'a'<br />
</code></p>
<p>Hope that makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on generators != lists (?) by nat</title>
		<link>http://www.zerbie.com/2008/03/25/generators-lists/#comment-13</link>
		<dc:creator>nat</dc:creator>
		<pubDate>Fri, 04 Apr 2008 18:26:48 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/03/25/generators-lists/#comment-13</guid>
		<description>follow(list(links)[1].url) perhaps?</description>
		<content:encoded><![CDATA[<p>follow(list(links)[1].url) perhaps?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on gimme that returned thing. by nat</title>
		<link>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-12</link>
		<dc:creator>nat</dc:creator>
		<pubDate>Fri, 04 Apr 2008 18:18:18 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-12</guid>
		<description>Pam,
naw, I didn't mean it in any practical sense.  It was just an existential musing of sorts -- life, the universe and everything, if you will.  I'm not even suggesting that the compartmentalized, strict paradigm of namespace and scope that I've experienced isn't a good thing, I'm just wondering if it's possible for it to be any other way.

I think the idea was somewhat more half-baked than you might be giving me credit for.</description>
		<content:encoded><![CDATA[<p>Pam,<br />
naw, I didn&#8217;t mean it in any practical sense.  It was just an existential musing of sorts &#8212; life, the universe and everything, if you will.  I&#8217;m not even suggesting that the compartmentalized, strict paradigm of namespace and scope that I&#8217;ve experienced isn&#8217;t a good thing, I&#8217;m just wondering if it&#8217;s possible for it to be any other way.</p>
<p>I think the idea was somewhat more half-baked than you might be giving me credit for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on generators != lists (?) by pam</title>
		<link>http://www.zerbie.com/2008/03/25/generators-lists/#comment-11</link>
		<dc:creator>pam</dc:creator>
		<pubDate>Fri, 04 Apr 2008 17:12:44 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/03/25/generators-lists/#comment-11</guid>
		<description>Hmmm. I think my problem is that showlinks() gives me something like this:

1. None ==&gt; /20484

Where the number is dynamically generated. I am not sure how to follow that link.</description>
		<content:encoded><![CDATA[<p>Hmmm. I think my problem is that showlinks() gives me something like this:</p>
<p>1. None ==> /20484</p>
<p>Where the number is dynamically generated. I am not sure how to follow that link.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on gimme that returned thing. by Paul Hummer</title>
		<link>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-10</link>
		<dc:creator>Paul Hummer</dc:creator>
		<pubDate>Fri, 04 Apr 2008 17:00:14 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-10</guid>
		<description>Pam-

  Variable scope was a hard thing for me to grasp when I first started programming.  When I started working in PHP, it made things worse...  :)  It's a difficult thing to explain to someone with very little programming experience, but a very valuable thing to understand, especially when you have a great language like python.

Paul</description>
		<content:encoded><![CDATA[<p>Pam-</p>
<p>  Variable scope was a hard thing for me to grasp when I first started programming.  When I started working in PHP, it made things worse&#8230;  <img src='http://www.zerbie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It&#8217;s a difficult thing to explain to someone with very little programming experience, but a very valuable thing to understand, especially when you have a great language like python.</p>
<p>Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on gimme that returned thing. by pam</title>
		<link>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-9</link>
		<dc:creator>pam</dc:creator>
		<pubDate>Fri, 04 Apr 2008 15:44:44 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-9</guid>
		<description>Do you mean, like, just declaring something to be global? Totally doable, but I feel our esteemed colleagues sending lightning bolts into my brain every time I even think about it. 

(That said, I'm sure there are good reasons to do it on occasion, but my usual reason would be, "I can't figure out a better way," which is not good enough.)</description>
		<content:encoded><![CDATA[<p>Do you mean, like, just declaring something to be global? Totally doable, but I feel our esteemed colleagues sending lightning bolts into my brain every time I even think about it. </p>
<p>(That said, I&#8217;m sure there are good reasons to do it on occasion, but my usual reason would be, &#8220;I can&#8217;t figure out a better way,&#8221; which is not good enough.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on generators != lists (?) by nat</title>
		<link>http://www.zerbie.com/2008/03/25/generators-lists/#comment-7</link>
		<dc:creator>nat</dc:creator>
		<pubDate>Fri, 04 Apr 2008 15:27:16 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/03/25/generators-lists/#comment-7</guid>
		<description>follow() doesn't just use the name of the link, you can also give it the link text, or the url, hell, even just part of the url. really anything that distinguishes it.</description>
		<content:encoded><![CDATA[<p>follow() doesn&#8217;t just use the name of the link, you can also give it the link text, or the url, hell, even just part of the url. really anything that distinguishes it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on gimme that returned thing. by nat</title>
		<link>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-6</link>
		<dc:creator>nat</dc:creator>
		<pubDate>Fri, 04 Apr 2008 15:12:56 +0000</pubDate>
		<guid>http://www.zerbie.com/2008/04/03/gimme-that-returned-thing/#comment-6</guid>
		<description>This actually prompted sort of an interesting thought yesterday.  Could you (would you/should you?) have some kind of operator (I don't mean in Python, just in general) that essentially popped a variable back up into the higher namespace?  All of the languages I've used have been pretty strict about scope, I don't know if there are others that play things a little looser.  Could you have a language without return values at all?  hmm, I think I need my own blog...</description>
		<content:encoded><![CDATA[<p>This actually prompted sort of an interesting thought yesterday.  Could you (would you/should you?) have some kind of operator (I don&#8217;t mean in Python, just in general) that essentially popped a variable back up into the higher namespace?  All of the languages I&#8217;ve used have been pretty strict about scope, I don&#8217;t know if there are others that play things a little looser.  Could you have a language without return values at all?  hmm, I think I need my own blog&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
