Bug or Feature: self.__varname only as self._ClassName__varname

Grégoire Dooms dooms at info.LESS.ucl.SPAM.ac.be
Wed Jun 16 02:49:18 EDT 2004


Feature, see
http://www.python.org/doc/current/tut/
section 9.6 Private Variables
--
Grégoire Dooms

Hans Georg Krauthaeuser wrote:
> Hi all,
> 
> I don't know if this is feature. For me it looks like a bug?!
> 
> ###########################################
> import sys
> 
> class CTest:
>     def __init__(self):
>         self.test="Test"
>         self._test="_Test"
>         self.__test="__Test"
> 
> if __name__ == "__main__":
>     t = CTest()
>     print t.test
>     print t._test
>     try:
>         print t.__test
>     except:
>         print sys.exc_type
>     print t._CTest__test
> ############################################
> The output is:
> 
> Test
> _Test
> exceptions.AttributeError
> __Test
> 
> 
> python is:
> Python 2.3.4 (#2, May 29 2004, 03:31:27)
> [GCC 3.3.3 (Debian 20040417)] on linux2
> 
> same on windows with python 2.3
> 
> Any comments?
> 
> Best regards
> Hans Georg



More information about the Python-list mailing list