Why can't Lists be private variables in a class
nholtz at docuweb.ca
Sun Mar 7 14:16:18 CET 2004
noelrivera at excite.com (fossil_blue) wrote in message news:<c7c33240.0403062142.6762c4d1 at posting.google.com>...
> Why we can't define a list as a private variable in a class such as
> __SYMTAB = [ ]
> class Myclass:
> def __init__(self):
> #some constructor here
> def __PlayWithList(arg1):
> # This doesn't work it compains about not having not having attribute
> index or append
> # Why?
> try: self.__SYMTAB.index(arg1)
> except ValueError: self.__SYMTAB.append(arg1)
> But it the list was public SYMTAB = [ ] it would work. Why?
Because of 'Private name mangling' (identifiers beginning with '__' and not ending
in '__' are considered private to the class) ?
More information about the Python-list