If I make a subclass of a built-in class, like this:

class mylist(list):
    def __init__(self):
        list.__init__(self)

Then it is valid for me to do this:

>>> x=mylist()
>>> x.hello=3
>>>

But I can't do this:

>>> y=list()
>>> y.hello=3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'hello'
>>>

What is it that is special about built-in classes that prevents you from adding methods or, uh, whatever the generic term is for sub- variables? Is there a way to make your own classes restricted like that?

OK thanks!


--
-dave----------------------------------------------------------------
Unfortunately, as soon as they graduate, our people return
to a world driven by a tool that is the antithesis of thinking:
PowerPoint. Make no mistake, PowerPoint is not a neutral tool —
it is actively hostile to thoughtful decision-making. It has
fundamentally changed our culture by altering the expectations
of who makes decisions, what decisions they make and how
they make them.  -Colonel T. X. Hammes, USMC

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to