Re: What is self.file = file for?

2008-05-14 Thread castironpi
On May 14, 2:26 am, Bruno Desthuilliers wrote: > afrobeard a écrit : > > (top-post corrected. Please, do not top-post). > > > > > > > On May 14, 3:08 am, [EMAIL PROTECTED] wrote: > >> Hello! > > >> I have trouble understanding something in this code snippet: > > >> class TextReader: > >>     """Pr

Re: What is self.file = file for?

2008-05-14 Thread Bruno Desthuilliers
afrobeard a écrit : (top-post corrected. Please, do not top-post). On May 14, 3:08 am, [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.fi

Re: What is self.file = file for?

2008-05-13 Thread Banibrata Dutta
__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.

Re: What is self.file = file for?

2008-05-13 Thread Gary Herron
Chester wrote: I see. A very good explanation indeed. Thank you for it. But why would anyone want to do this anyway? In a single sentence, OOP (Object Oriented Programming) is a way to organize a program around your data and the operations on that data. Many books and college courses are

Re: What is self.file = file for?

2008-05-13 Thread afrobeard
If you are familiar to C++ or a similar language, the concept of the this pointer might not be alien to you. self in this context is basically a reference to the class itself. Hence self.file is creating a class member and setting to the input from file. As Gary pointed out, during initialization,

Re: What is self.file = file for?

2008-05-13 Thread Daniel Fetchinson
> 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 d

Re: What is self.file = file for?

2008-05-13 Thread Gary Herron
[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

What is self.file = file for?

2008-05-13 Thread wxPythoner
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