__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.
'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. On 5/14/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello! > > I have trouble understanding something in this code snippet: > > class TextReader: > """Print and number lines in a text file.""" > def __init__(self, file): > self.file = file > . > . > . > > > When would you do a thing like self.file = file ? I really don't > find an answer on this. Please help me understand this. > -- > http://mail.python.org/mailman/listinfo/python-list > -- regards, Banibrata http://www.linkedin.com/in/bdutta http://octapod.wordpress.com
-- http://mail.python.org/mailman/listinfo/python-list