标签:python
可以检查参数,一直没注意这个语言特性,忽略了很多细节,感谢 vitrox
class Person( object ): def __init__( self, name ): if not isinstance( name, str ): raise TypeError( '...' ) else: self.__name = name @property def name( self ): print 'get name.' return self.__name @name.setter def name( self, newname ): print 'set name.' if not isinstance( newname, str ): raise TypeError( '...' ) else: self.__name = newname print 'set ok.' p = Person( 'A' ) p.name = 'B' print p.name
python property属性,布布扣,bubuko.com
标签:python
原文地址:http://blog.csdn.net/pandora_madara/article/details/36091775