<?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"
	>
<channel>
	<title>Comments on: Duck typing and Python</title>
	<atom:link href="http://www.remyroy.com/2008/06/01/duck-typing-and-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.remyroy.com/2008/06/01/duck-typing-and-python/</link>
	<description>software development, technology, science and philosophy by Rémy Roy</description>
	<pubDate>Sat, 31 Jul 2010 05:26:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Rémy Roy</title>
		<link>http://www.remyroy.com/2008/06/01/duck-typing-and-python/#comment-11083</link>
		<dc:creator>Rémy Roy</dc:creator>
		<pubDate>Sun, 15 Mar 2009 20:42:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.remyroy.com/2008/06/01/duck-typing-and-python/#comment-11083</guid>
		<description>Hello Carla,

A good example of this would be the file like objects used in Python. In various modules, you can use file like objects for different input/ouput operations.

For instance, take the pickle module: http://docs.python.org/library/pickle.html . It provides object de/serialization. It requires a file object for loading or dumping object. If you were to use an old tape component where there is no built in mechanism to access it, you could create a Tapefile class simply by specifying the few methods required by pickle. It could look like this:

class Tapefile():
    "A tape file"
    def __init__(self,params):
        #various initialization for tape access
        pass
    def read(len):
        #use special methods to access tape
        pass
    def readline():
        #use special methods to read a whole line on tape
        pass
    def write(value):
        #use special methods to write on tape
        pass

You could than pass a Tapefile object to the pickle module and it would simply work. The pickle module do not care if it has a file object or another object pretending to act like a file. As long as it has the right methods, it will work.</description>
		<content:encoded><![CDATA[<p>Hello Carla,</p>
<p>A good example of this would be the file like objects used in Python. In various modules, you can use file like objects for different input/ouput operations.</p>
<p>For instance, take the pickle module: <a href="http://docs.python.org/library/pickle.html" rel="nofollow">http://docs.python.org/library/pickle.html</a> . It provides object de/serialization. It requires a file object for loading or dumping object. If you were to use an old tape component where there is no built in mechanism to access it, you could create a Tapefile class simply by specifying the few methods required by pickle. It could look like this:</p>
<p>class Tapefile():<br />
    &#8220;A tape file&#8221;<br />
    def __init__(self,params):<br />
        #various initialization for tape access<br />
        pass<br />
    def read(len):<br />
        #use special methods to access tape<br />
        pass<br />
    def readline():<br />
        #use special methods to read a whole line on tape<br />
        pass<br />
    def write(value):<br />
        #use special methods to write on tape<br />
        pass</p>
<p>You could than pass a Tapefile object to the pickle module and it would simply work. The pickle module do not care if it has a file object or another object pretending to act like a file. As long as it has the right methods, it will work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carla</title>
		<link>http://www.remyroy.com/2008/06/01/duck-typing-and-python/#comment-10958</link>
		<dc:creator>Carla</dc:creator>
		<pubDate>Tue, 10 Mar 2009 05:47:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.remyroy.com/2008/06/01/duck-typing-and-python/#comment-10958</guid>
		<description>is it possible you could display an example of duck typing with python...</description>
		<content:encoded><![CDATA[<p>is it possible you could display an example of duck typing with python&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
