<?xml version="1.0"?><feed xmlns="http://www.w3.org/2005/Atom"><title>CafePy.com Articles</title><link rel="alternate" type="text/html" href="http://www.cafepy.com/article/feed"/><updated>2009-11-19T00:20:46.854681Z</updated><author><name></name></author><id>urn:cafepy.com:articles</id><entry><title>Be Pythonic</title><link href="http://www.cafepy.com/article/be_pythonic/"/><id>be_pythonic</id><updated>2009-11-19T00:20:46.854681Z</updated><content type="html">&lt;p&gt;This article is intended for new users of Python.&lt;/p&gt;
&lt;p&gt;When going from one language to another, some things have to be &lt;em&gt;unlearned&lt;/em&gt; (see &lt;a href=&quot;http://education.calumet.purdue.edu/vockell/EdPsyBook/Edpsy6/edpsy6_transfer.htm&quot;&gt;Transfer of Learning&lt;/a&gt;). What you know from other languages may not be always useful in Python. This page contains some idioms used in Python that I particularly like, and I hope others find useful in their quest for Pythonicity.&lt;/p&gt;
&lt;h1&gt;You need counters rarely, and iterators only occasionally&lt;/h1&gt;
&lt;p&gt;Wrong:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
     &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Pythonic:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The following example indexes a list.&lt;/p&gt;
&lt;p&gt;Wrong:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Pythonic:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;An iterator variable is useful when you want to maintain looping state between two &#39;runs&#39;:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;itrL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itrL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;do_something&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;is_some_condition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itrL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;# continues where previous loop left off&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;do_something_else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h1&gt;You may not need that &lt;code&gt;for&lt;/code&gt; loop&lt;/h1&gt;
&lt;p&gt;Python provides many higher level facilities to operate on sequences, such as &lt;code&gt;zip()&lt;/code&gt;, &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;min()&lt;/code&gt;, &lt;a href=&quot;http://docs.python.org/tutorial/datastructures.html#list-comprehensions&quot;&gt;list comprehensions&lt;/a&gt;, &lt;a href=&quot;http://docs.python.org/reference/expressions.html#generator-expressions&quot;&gt;generator expressions&lt;/a&gt; and so on. See &lt;a href=&quot;http://docs.python.org/library/functions.html&quot;&gt;Built-in Functions&lt;/a&gt; for these functions and more. &lt;/p&gt;
&lt;p&gt;Keep data in tuples, lists and dictionaries, and operate on entire collections for that fuzzy Pythonic feeling.  For example, here is some code that reads a CSV file (with first row being the field names), converts each line into a dictionary record, and calculates the sum on the &#39;quantity&#39; column:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;filename.csv&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                    &lt;span class=&quot;c&quot;&gt;# f is an iterator&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;field_names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;         &lt;span class=&quot;c&quot;&gt;# get the first item from the iterator using next()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;records&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field_names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# this will pull remaining lines&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;quantity&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;record&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Though a little naive (you should be using the &lt;a href=&quot;http://docs.python.org/library/csv.html&quot;&gt;&lt;code&gt;csv&lt;/code&gt;&lt;/a&gt; module anyway, which is part of the &lt;a href=&quot;&quot;&gt;Python Standard Library&lt;/a&gt;), this example demonstrates some useful features. Using &lt;code&gt;zip()&lt;/code&gt; with &lt;code&gt;dict()&lt;/code&gt; you can combine a tuple of field names with a tuple of values and make a dictionary - combine with list comprehensions you can do this to an entire list in one go.&lt;/p&gt;
&lt;h1&gt;Tuples are not read-only lists&lt;/h1&gt;
&lt;p&gt;Tuples usually indicate a &lt;em&gt;heterogenous&lt;/em&gt; collection, for example &lt;code&gt;(first_name, last_name)&lt;/code&gt; or &lt;code&gt;(ip_address, port)&lt;/code&gt;. Note that the &lt;em&gt;type&lt;/em&gt; may be same (as in &lt;code&gt;first_name&lt;/code&gt; and &lt;code&gt;last_name&lt;/code&gt; may both be strings), but the real world meaning is usually different. You can think of a tuple as a row in a relational database - in fact the database row is even called a tuple in formal descriptions of the relational model.  By contrast, a list of names is always a list, even though a particular function may not change it, that does not make it a tuple.&lt;/p&gt;
&lt;p&gt;Tuple unpacking is a useful technique to extract values from a tuple. For example:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;all_connections&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Connected to &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; on &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Reading this code tells you that &lt;code&gt;all_connections&lt;/code&gt; is a list (or iterable) contaning tuples of the form &lt;code&gt;(ip_address, port)&lt;/code&gt;. This is much clearer than using &lt;code&gt;for item in all_connections&lt;/code&gt; and then poking inside &lt;code&gt;item&lt;/code&gt; using &lt;code&gt;item[0]&lt;/code&gt; or similar techniques.&lt;/p&gt;
&lt;p&gt;Unpacking is also useful while returning multiple values from a function:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ext&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;# split a file name into first part and extension&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h1&gt;Classes are not for grouping utility functions&lt;/h1&gt;
&lt;p&gt;C# and Java can have code only within classes, and end up with many &lt;em&gt;utility&lt;/em&gt; classes containing only static methods. A common example is a math functions such as &lt;code&gt;sin()&lt;/code&gt;. In Python you just use a module with the top level functions.&lt;/p&gt;
&lt;h1&gt;Say no to getter and setter methods&lt;/h1&gt;
&lt;p&gt;Yes, &lt;em&gt;encapsulation&lt;/em&gt; is important. No, getters and setters are not the only way to implement encapsulation. In Python, you can use a &lt;a href=&quot;http://docs.python.org/library/functions.html#property&quot;&gt;&lt;code&gt;property&lt;/code&gt;&lt;/a&gt; to replace a member variable and completely change the implementation mechanism, with &lt;em&gt;no change&lt;/em&gt; to any calling code.&lt;/p&gt;
&lt;h1&gt;Functions are objects&lt;/h1&gt;
&lt;p&gt;A function is a object that happens to be callable. This example sorts a list of dictionaries based on the value of &#39;price&#39; key in the dictionaries:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#  define a function that returns useful data from within an object&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_price&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;price&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_price&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c&quot;&gt;# sort a list using the [&amp;#39;price&amp;#39;] value of objects in the list&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You can also use &lt;code&gt;sorted(L, key=get_price)&lt;/code&gt; to return a new list instead of modifying the list in-place.&lt;/p&gt;
&lt;h1&gt;Related Links&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://dirtsimple.org/2004/12/python-is-not-java.html&quot;&gt;Python is not Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0&quot;&gt;What is Pythonic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This article originally appeared at http://shalabh.infogami.com/Be_Pythonic2&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.cafepy.com/article/be_pythonic/#comments&quot;&gt;Comments&lt;/a&gt;</content></entry><entry><title>Python Types and Objects</title><link href="http://www.cafepy.com/article/python_types_and_objects/"/><id>python_types_and_objects</id><updated>2009-11-15T03:17:19.281433Z</updated><content type="html">&lt;h1&gt;Abstract&lt;/h1&gt;
&lt;p&gt;Explains different Python new-style  objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what are the &lt;code&gt;&amp;lt;type &#39;type&#39;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;type &#39;object&#39;&amp;gt;&lt;/code&gt; types&lt;/li&gt;
&lt;li&gt;how user defined classes and instances are related to each other and to built-in types&lt;/li&gt;
&lt;li&gt;what are metaclasses&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The system described is sometimes called the Python type system, or the object model.&lt;/p&gt;
&lt;h1&gt;Read The Book&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;python_types_and_objects.html&quot;&gt;Single HTML Page&lt;/a&gt; 
    [ &lt;a href=&quot;python_types_and_objects_single.zip&quot;&gt;zip&lt;/a&gt; |
      &lt;a href=&quot;python_types_and_objects_single.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;contents.html&quot;&gt;Multiple HTML Page&lt;/a&gt;
    [ &lt;a href=&quot;python_types_and_objects_chunky.zip&quot;&gt;zip&lt;/a&gt; |
      &lt;a href=&quot;python_types_and_objects_chunky.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;python_types_and_objects.pdf&quot;&gt;PDF&lt;/a&gt; 
   [ &lt;a href=&quot;python_types_and_objects_pdf.zip&quot;&gt;zip&lt;/a&gt; |
     &lt;a href=&quot;python_types_and_objects_pdf.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Related&lt;/h1&gt;
&lt;p&gt;This book is part of a series:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Python Types and Objects [you are here]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/article/python_attributes_and_methods/&quot;&gt;Python Attributes and Methods&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;a href=&quot;http://www.cafepy.com/article/python_types_and_objects/#comments&quot;&gt;Comments&lt;/a&gt;</content></entry><entry><title>Python Attributes and Methods</title><link href="http://www.cafepy.com/article/python_attributes_and_methods/"/><id>python_attributes_and_methods</id><updated>2009-11-15T03:17:10.946682Z</updated><content type="html">&lt;h1&gt;Abstract&lt;/h1&gt;
&lt;p&gt;Explains the mechanics of attribute access for new-style Python objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how functions become methods&lt;/li&gt;
&lt;li&gt;how descriptors and properties work&lt;/li&gt;
&lt;li&gt;method resolution order for classes&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Read The Book&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;python_attributes_and_methods.html&quot;&gt;Single HTML Page&lt;/a&gt; 
   [ &lt;a href=&quot;python_attributes_and_methods_single.zip&quot;&gt;zip&lt;/a&gt; | 
     &lt;a href=&quot;python_attributes_and_methods_single.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;contents.html&quot;&gt;Multiple HTML Pages&lt;/a&gt; 
   [ &lt;a href=&quot;python_attributes_and_methods_chunky.zip&quot;&gt;zip&lt;/a&gt; | 
     &lt;a href=&quot;python_attributes_and_methods_chunky.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;python_attributes_and_methods.pdf&quot;&gt;PDF&lt;/a&gt; 
   [ &lt;a href=&quot;python_attributes_and_methods_pdf.zip&quot;&gt;zip&lt;/a&gt; | 
     &lt;a href=&quot;python_attributes_and_methods_pdf.tar.gz&quot;&gt;tar.gz&lt;/a&gt; ]&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Related&lt;/h1&gt;
&lt;p&gt;This book is part of a series:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/article/python_types_and_objects/&quot;&gt;Python Types and Objects&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Python Attributes and Methods  [you are here]&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;a href=&quot;http://www.cafepy.com/article/python_attributes_and_methods/#comments&quot;&gt;Comments&lt;/a&gt;</content></entry></feed>