[Pythonmac-SIG] Strange behavior with W

Just van Rossum just@letterror.com
Fri, 14 Jul 2000 19:56:36 +0100


At 9:20 PM -0400 13-07-2000, Gordon Worley wrote:
>In a program I have, I first create a class that inherits from
>W.Window and can be called Document for our purposes.  In the
>Document, there is an instance of W.List called list.  Document
>sometimes calls a class to edit items in this list called
>List_Editor.  Among other things, List_Editor takes a Document object
>as an argument.  When finishing up, the code that makes the change
>looks something like this (note:  up in __init__, the passed Document
>is put into self.document):
>
>self.document.list[index] = self.w.display.get()
>
>Which does what might be expected of it.  Yet this next line of code
>will do the same thing:
>
>self.document.w.list[index] = self.w.display.get()
>
>Yet Document never creates any object called w, much less put
>anything in it.  While I realize that complaining about my program
>working isn't necessarily the best thing to do, this behavior, to me
>at least, does not seem normal.  How can this be happening?

So there should be no attribute called 'w'? Are you sure the Document class
never assigns to self.w? The W.Window class certianly doesn't:

>>> import W
>>> w = W.Window((100, 100))
>>> w.open()
>>> w.w
Traceback (innermost last):
  File "<input>", line 1, in ?
  File "DevDev:PyPy:Python  current:Mac:Tools:IDE:Wwindows.py", line 406,
in __getattr__
    raise AttributeError, attr
AttributeError: w
>>>

Any chance you're playing with __getattr__? (W.Window does...)

Just