[Twisted-Python] What's the purpose of __?
Phil Christensen
phil at bubblehouse.org
Tue Feb 15 17:03:21 EST 2011
On Feb 15, 2011, at 5:36 AM, Attila Nagy wrote:
> Hi,
>
> I'm trying to do an LMTP implementation based on smtp.py and came to the
> issue of class private variables with double underscores.
> Examples:
> http://twistedmatrix.com/trac/browser/trunk/twisted/mail/smtp.py#L746
> http://twistedmatrix.com/trac/browser/trunk/twisted/mail/smtp.py#L815
> and a lot of occurrences in this file.
>
> This makes me a problem, because I override some functions in a class,
> named LMTP, so these cannot work together.
>
> What's the rationale of using these, instead of static names?
I've got no idea of the rationale for using double-underscore notation, but why does that prevent you from subclassing it? Just add the class name to it for access:
class A:
def __init__(self):
self.__test = 'test'
a = A()
print a._A__test
-phil
More information about the Twisted-Python
mailing list