More python fun...

Jun 21, 2007 12:07


class A(object):
def __init__(self):
self.__my_var = 'a'

class B(A):
def foo(self):
print self.__my_var

error:

AttributeError: 'B' object has no attribute '_B__my_var'You learn something new everyday. Apparently prefixing with __ in classes in python causes the interpreter to mangle the name. This makes a "private" variable. ( Read more... )

Leave a comment

Comments 2

thedutch June 21 2007, 21:02:59 UTC
what high level language do you think minimizes exposure to low level details?

Reply

evan June 21 2007, 22:10:08 UTC
all of 'em except perl. :)

Reply


Leave a comment

Up