On Aug 30, 12:18 pm, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I have read that you can derive from the base classes such as str, > > list, dict. > > > I guess this would look like: > > > def MyString(str): > > def MyList(list): > > def MyDict(dict): > > Well, replace 'def' with 'class' and you're right. > > > How do you access the data that is contained in the super class? > > This way: > >>> class MyList(list): > ... def do_something(self): > ... self.append(3) > ... print self > ... > >>> l = MyList((1, 2)) > >>> l > [1, 2] > >>> l.do_something() > [1, 2, 3] > > That is: Whenever you want to refer to the value refer to self (that is, > refer to the instance of your class). > > /W
Ok, thanks. So it's: class MyString(str): def __init__(self,strInput): self = strInput -- http://mail.python.org/mailman/listinfo/python-list