Christopher Spears wrote:
>>class MyList:
>> def __init__(self, aList=None):
>> if aList is None:
>> self._list = []
>> else:
>> self._list = aList[:]
>>
>
>
> This code certainly looks like it will do the trick.
> I'm just not sure what the _ in front of list (i.e.
> _list
> class MyList:
>def __init__(self, aList=None):
> if aList is None:
>self._list = []
> else:
>self._list = aList[:]
>
This code certainly looks like it will do the trick.
I'm just not sure what the _ in front of list (i.e.
_list) denotes.
"I'm the last person t
> Write a class called Mylist that shadows ("wraps") a
> Python list: it should overload most list operators
> ...
> When I read this, I feel like a deer caught in the
> headlights. Where should I begin? How do I go about
> designing a new class?
Well, to quote an old joke, I wouldn't start from
# initialization of class
If you want to be able to give initial values to the class when it
is instantialized, you do it in the __init__ function that Terry
mentioned:
class People(object):
def __init__(self, firstname='Chris', lastname='Spears'):
On 1/26/06, Christopher Spears <[EMAIL PROTECTED]> wrote:
> headlights. Where should I begin? How do I go about
> designing a new class?
Some starter 101:
First, recognize that a class is a compound type that is not only a type
but binds other variables and methods with it.
#-
On Thu, 26 Jan 2006, Christopher Spears wrote:
> Here is an exercise out of Learning Python:
Which edition? If I recall, the second edition covers through a release
of Python (2.2?) that permits direct subclassing of lists; while the
earlier one came out prior to Python 2.2, and would expect you
Here is an exercise out of Learning Python:
Write a class called Mylist that shadows ("wraps") a
Python list: it should overload most list operators
and operations including +, indexing, iteration,
slicing, and list methods such as append and sort.
See the Python reference manual for a list of po