how come .insert() don't work

David M. Cooke cookedm+news at physics.mcmaster.ca
Wed Oct 27 23:46:58 EDT 2004


Bennie <bennie at rotzjes.nl> writes:
> Martin v. Löwis wrote:
>> Bennie wrote:
>>
>>> def tekst_in(self, tag):
>>>         tekst_tag={'p': '\t\t<p>\n\n\t\t</p>\n', 'br': '<br />'}
>>>         self.tekst.insert(INSERT, tekst_tag[tag])
>>>
>>> Then I get a AttributeError...
>>> I seached the net, can come op white a answer.
>> What specific attribute is mentioned in the AttributeError?
>> That self has no attribute tekst, or that self.tekst has
>> no attribute insert?
>> If the former, you need to arrange your class so that self has
>> an attribute tekst (e.g. by initializing tekst in __init__).
>> If the latter: what kind of thing is self.tekst?
>> Regards,
>> Martin
> self.tekst is a Tkinter.Text() so it has a insert attribute, .insert()

See, you should have mentioned that before. What you should also
mention is:

1) the _exact_ text of the traceback. Saying "I get an AttributeError"
   is not nearly enough: the full message has info that
   people-in-the-know know how to interpret. Copy-and-paste it.

2) the smallest (or so) of *working* code that will exhibit the error.
   The snippet in your original post doesn't work. Again, copy-and-paste.

Basically, put enough info in your question that we don't have to read
your mind.

Now I'll put my mind-reading cap on...

- Are you sure that tekst_in() is a method, not a function? The
  indentation suggests function, while the self parameter suggests method.

- Are you positive self.tekst is a Tkinter.Text()? Throw in some
  print statements to check. 'print repr(self)' is a good one.

- tekst_tag[tag] shouldn't be the problem (as suggested by your
  original post), as that would raise a KeyError, not an AttributeError.

  etc.

(I'll bet once you've done what I've suggested, you'll have found the bug...)

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list