<?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: User-defined iterators in Python</title>
	<atom:link href="http://inspirated.com/2009/05/14/user-defined-iterators-in-python/feed" rel="self" type="application/rss+xml" />
	<link>http://inspirated.com/2009/05/14/user-defined-iterators-in-python</link>
	<description>krkhan&#039;s blog</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:55:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: krkhan</title>
		<link>http://inspirated.com/2009/05/14/user-defined-iterators-in-python/comment-page-1#comment-38578</link>
		<dc:creator>krkhan</dc:creator>
		<pubDate>Mon, 13 Dec 2010 23:48:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.inspirated.com/wordpress/?p=219#comment-38578</guid>
		<description>Ray, you have to use the __setitem__ method to override [] operator. Here&#039;s an example:

&lt;blockquote&gt;&lt;code&gt;&gt;&gt;&gt; class A:
...     def __setitem__(self, index, value):
...             print index, value
... 
&gt;&gt;&gt; a = A()
&gt;&gt;&gt; a[23] = 45
23 45&lt;/code&gt;&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>Ray, you have to use the __setitem__ method to override [] operator. Here&#8217;s an example:</p>
<blockquote><p><code>&gt;&gt;&gt; class A:<br />
...     def __setitem__(self, index, value):<br />
...             print index, value<br />
...<br />
&gt;&gt;&gt; a = A()<br />
&gt;&gt;&gt; a[23] = 45<br />
23 45</code></p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray Wood</title>
		<link>http://inspirated.com/2009/05/14/user-defined-iterators-in-python/comment-page-1#comment-38570</link>
		<dc:creator>Ray Wood</dc:creator>
		<pubDate>Mon, 13 Dec 2010 21:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.inspirated.com/wordpress/?p=219#comment-38570</guid>
		<description>I was able to use this info to make one of my user defined classes iterable. Which is to say that I was able to iterate thru it with a &quot;for x in foobar&quot; statement.

But, apparently, this approach does not allow you to use the &#039;[]&#039; index selection syntax as is foobar[2]. Is there some additional method you have to add to your defined class for this, or it is that strictly for Python built-in types?</description>
		<content:encoded><![CDATA[<p>I was able to use this info to make one of my user defined classes iterable. Which is to say that I was able to iterate thru it with a &#8220;for x in foobar&#8221; statement.</p>
<p>But, apparently, this approach does not allow you to use the &#8216;[]&#8216; index selection syntax as is foobar[2]. Is there some additional method you have to add to your defined class for this, or it is that strictly for Python built-in types?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.617 seconds -->

