Adding static typing to Python
Jason Orendorff
jason at jorendorff.com
Tue Feb 19 12:43:14 EST 2002
Fernando Perez wrote:
> Courageous wrote:
> > One of the things I like about C sharp is their use of attributes,
>
> Just curious, isn't there something quite similar to what you describe in
> py2.2? I've only glanced at it so I could be wrong...
Yes.
import re
class Frob(object):
def get_name(self):
return self.__name
def set_name(self, name):
if re.match('^\w+$', name) is None:
raise ValueError("Frob.name may only contain name characters")
self.__name = name
name = property(get_name, set_name, None,
""" The Frob's canonical given name """)
Guido hints there may be some syntactic sugar for this
in an upcoming version.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list