On Sat, 08 Dec 2007 11:23:57 -0800, MonkeeSage wrote: >> > The equivalent python idiom is something like: >> >> > class A: >> > __a = "foo" >> > def __init__(self): >> > self.a = A.__a [...] >> > Which roughly translates to this in ruby: >> >> > class A >> > attr_accessor :a >> > def initialize >> > @a = "foo" >> > end >> > end [...] > Not really. In ruby an ivar is accessible within the class *only*, but > not from without (like a mangled python class var), unless you declare > an accessor (or write the accessor methods yourself). So my example is > closer, and is not a WTF, if you know how ruby works.
In your python example, the class attribute is mangled, but the instance attribute isn't, whereas your ruby code has no class attribute, and an instance attribute that isn't (directly) accessible outside the class. The equivalent in python would involve a mangled instance attribute, like: class A(object): def __init__(self): self.__a = "foo" def get_a(self): return self.__a def set_a(self, val): self.__a = val a = property(get_a, set_a) -- http://mail.python.org/mailman/listinfo/python-list