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
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
__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.
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
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,
> 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
[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
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