[Python-ideas] C# style properties
Georg Brandl
g.brandl at gmx.net
Thu Jul 12 23:10:26 CEST 2007
Josiah Carlson schrieb:
> Christian Heimes <lists at cheimes.de> wrote:
>>
>> Hello!
>>
>> In the past few months I've been toying around with .NET, C# and
>> PythonNet. While I still think that C# is too wory (public static
>> explicit operator Egg(Spam spam) { ... }) C# has one syntax feature I
>> really like to see in Python.
>>
>> private float _a
>> public float a
>> {
>> get { return _a; }
>> set { _a = value; }
>> }
> [snip]
>> Comments?
>
> Python has an exact equivalent to the C# method (which uses a new
> block/scope for defining properties...)
>
> class foo:
> class a(Property):
> ''' documentation '''
> def get(self):
> return self._a
> def set(self, val):
> self._a = val
> def de1(self):
> del self._a
>
>
> Now all you need is a Property base class with a proper metaclass that
> handles all of the magic for you. I'm curious as to why this still gets
> brought up when the obvious syntax is more or less identical to
> basically all reasonable alternate syntaxes. Is it because people don't
> understand that metaclasses can mangle your class any way they want?
No, it's because they feel that the word "class" to introduce a property
is ugly, and I can't blame them for it.
Georg
More information about the Python-ideas
mailing list