Skynet

---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

这个函数,好像有 。net的影子

class C(object):
    
def __init__(self): self._x = None
    
def getx(self): print "get x";return self._x
    
def setx(self, value): print "set x"; self._x = value
    
def delx(self): print "del x";del self._x
    x 
= property(getx, setx, delx, "I'm the 'x' property.")


使用
>>> t=C()
>>> t.x
get x
>>> t.x="en"
set x
>>> print t.x
get x
en
>>> del t.x
del x
>>> t.x
get x


整理 www.blogjava.net/Good-Game
posted on 2009-01-14 10:25 刘凯毅 阅读(1191) 评论(0)  编辑  收藏 所属分类: python

只有注册用户登录后才能发表评论。


网站导航: