I want to see all the variables

johnf jfabiani at yolo.com
Sat Dec 30 14:08:10 EST 2006


Steven D'Aprano wrote:


> 
> There are three other underscore conventions in use:
> 
> (1) Objects with a single leading underscore like _attribute are private
> by convention, but Python doesn't enforce it. Starting an object with a
> single underscore is like writing "# Private! Don't touch!" after it.
> 
> (2) By convention, if you want to create a name that is the same as a
> built-in object without shadowing (hiding) the built-in, put a single
> trailing underscore after it like "file_". That's just a style convention
> though, you are free to call it FiLE ,or anything else, if you prefer.
> 
> (3) Last but not least, class attributes with two leading and trailing
> underscores are considered special but public, like __init__ and __repr__.
> It is probably a bad idea to invent your own.
> 
> 
> 
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".  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.  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.

Thanks 
Johnf



More information about the Python-list mailing list