johnf wrote: > Very detailed. But I was attempting to debug some code which subclassed > other code. I got a traceback that something like "no > mySubClass.__source.query() did not exist".
By (strong) convention, "__" means "not to be accessed from outside the class, not even from subclasses". The author of the original class does not want you to access that attribute. > The superclass had something > like "myClass.__source.query(sql)" which worked > but "mySubClass.__source.query(sql)" did not work. So I tried to debug > using "dir(myClass.__source)" and got an error. "dir(myClass._myClass__source)" should work, as should "dir(mySubClass._myClass__source)" and "mySubClass._myClass__source". But remember that it is usually really bad style to do this and that there is probably a reason why the author of myClass does not want you to do that. If myClass was written by yourself, simply do not use "__". Only use "__" when you really know why you are doing it. Otherwise, just use "_". See also: http://docs.python.org/ref/atom-identifiers.html > And I also got error when > I "dir(mySubClass.__source". So how could I have debugged the problem if > dir() will not display information on the __source? I hope that explains > my issue. A simple dir() on myClass could have given you a hint on what happens with __source. -- René OpenPGP key id: 0x63B1F5DB JID: [EMAIL PROTECTED]
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list