what is self._base?
maxm
maxm at mxm.dk
Fri Dec 14 07:58:09 EST 2001
"Benjamin Tai" <bt98 at doc.ic.ac.uk> wrote in message
news:3C19EC50.153B76A1 at doc.ic.ac.uk...
> However I can't find any documents/explanation for the following:
>
> 1) What is "_base"
"_base" is an attribute on the object that can contain any Python objects.
It could alse be called base, Base, __base etc. The leading underscore
indicates that it is a private attribute, that should only be used by the
class itself. This is just a convention, and is not enforced by the
language.
So even though you shouldn't you could call it via:
stack = Stack()
print stack._base
>>> some_kind_of_stack_object
> 2) What is "start=None"
It is a default parameter passed to the __init__ method. It means that it
has not been assigned a more meaningfull value.
If you create the object with a parameter, you could do it like:
stack = Stack('Spam egg')
print stack._base
>>> Spam egg
or like this which is in effect the same.
stack = Stack(start='Spam egg')
print stack._base
>>> Spam egg
> 3) Why can't I just write "self = stacktype.Stack()"
Oh but you can ... it would just not do what you excpect ;-)
What if you have more than one attribute. How would you call them then.
ie.::
self = 'Max M'
self = 'Rasmussen'
self = 'Denmark'
self.firstName = 'Max M'
self.lastname = 'Rasmussen'
self.country = 'Denmark'
Without the attribute name you could not adress the values again. And by
setting self to a string or any other object you are in effect changing the
object to something else.
I would recommend that you get a hold of the excellent "Learning Python"
book, that does a great job at explaining the fundemantals of Python. It
will save you a lot of time in the long run.
regards Max M
More information about the Python-list
mailing list