12 Jul 2007 17:43
C# style properties
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; }
}
I think it's a very nice way to define a variable that acts similar to
Python properties. get, set and value are part of the syntax.
Python has no nice way to define a property with set and get. You always
have to use lambda or some private methods.
class Now:
_a = 0.0
<at> property
def a(self):
"""Read only property
return self._a
def _geta(self):
return self._a
def _seta(self, value):
(Continue reading)
RSS Feed