
deets at nospam
Nov 20, 2009, 8:46 AM
Post #2 of 3
(172 views)
Permalink
|
King schrieb: > class A(object): > def __init__(self, value=0.): > self.value = value > > class B(A): > def __init__(self, value=None): > A.__init__(self) > self.value = value > > obj = B() > > When "B" initializes, it overwrite "value" variable of "A". How do I > make sure that no variable should not be defined with names of "A" in > "B"? To avoid these kinds of clashes, you can use the double-undescore syntax. It will create a mangled name that looks like _module_class_variablename By this, the two different variable get distinct names. *However*, this is neither a proper way of making variables private, nor are name-clashes something that should arise more than every now-and-then. Instead, try rather renaming value to something more meaningful. Diez -- http://mail.python.org/mailman/listinfo/python-list
|