what is self._base?
chris.gonnerman at newcenturycomputers.net
Fri Dec 14 08:06:21 EST 2001
----- Original Message -----
From: "Benjamin Tai" <bt98 at doc.ic.ac.uk>
> I have come across the following statement in a constructor (Programming
> Python by Mark Lutz). After extending a type in C (stacktype), it is
> wrapped by a Python class (Stack).
> import stacktype
> class Stack:
> def __init__(self, start=None):
> self._base = start or stacktype.Stack()
> However I can't find any documents/explanation for the following:
> 1) What is "_base"
Without the rest of the class it's hard to say for sure, but it appears to
be a container for the stacktype.Stack() object that this Stack class is
> 2) What is "start=None"
An argument definition for an arg named "start" which by default will be
if the programmer doesn't provide it.
> 3) Why can't I just write "self = stacktype.Stack()"
Because self is the Python class instance for Stack; changing it as you
suggest in local scope won't change anything, and if it did it would be the
wrong thing to do.
> Any help for this newbie would be appreciated.
When you "wrap" a C extension class you are usually doing so to make a
non-object oriented C 'thing' (I am loathe to say 'object' here) behave as
an object-oriented Python 'thing'. So, you generally have some instance
attribute (such as _here in this case) to contain the C 'thing' which you
wrapping; then you define methods to act on this 'thing' and voila, you have
More information about the Python-list