<div>__init__() is the object-constructor for TextReader class, accepting an argument 'file' (reference to an Object). TextReader has a member variable / attribute, called 'file' too (same name as the argument to __init__()). The constructor is invoked when an object of TextReader class is being create. At that point, the construct binds the reference of the passed file object, to it's own instance-variable.<br>
 </div>
<div>'self' is the equivalent of 'this' pointer in C++ as others have mentioned. So 'self.file' is referring to the instance variable, on the left-hand-side of the assignment operation, and the 'file' on the right-hand-side is the method argument.<br>
 </div>
<div><span class="gmail_quote">On 5/14/08, <b class="gmail_sendername"><a href="mailto:wxPythoner@gmail.com">wxPythoner@gmail.com</a></b> <<a href="mailto:wxPythoner@gmail.com">wxPythoner@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello!<br><br>I have trouble understanding something in this code snippet:<br><br>class TextReader:<br>   """Print and number lines in a text file."""<br>
   def __init__(self, file):<br>       self.file = file<br>       .<br>       .<br>       .<br><br><br>When would you do a thing like  self.file = file  ? I really don't<br>find an answer on this. Please help me understand this.<br>
--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br><br clear="all"><br>-- <br>regards,<br>Banibrata<br><a href="http://www.linkedin.com/in/bdutta">http://www.linkedin.com/in/bdutta</a><br>
<a href="http://octapod.wordpress.com">http://octapod.wordpress.com</a>