【发布时间】:2014-03-04 20:49:55
【问题描述】:
我收到错误“类型错误:'locationTile' 在尝试调用其 fdel() 方法时不是可调用对象。代码:
class GamePlayLocationTiles(object):
"""The stuff needed for game play"""
_locationTiles = []
def locationTiles():
doc = "property locationTiles's doc string"
def fget(self):
return self._locationTiles[0]
def fset(self, value):
self._locationTiles = value[0]
def fdel(self):
del self._locationTiles[0]
return locals() # credit: David Niergarth
locationTiles = property(**locationTiles())
def __init__(self):
self.fill_location_tiles_list()
不同的模块:
import game_play_model
class GamePlayController:
"""perform operations on the game_play_model"""
def __init__(self):
self.the_game_location_tiles = game_play_model.GamePlayLocationTiles()
self.shuffle_location_tiles()
def shuffle_location_tiles(self):
self.the_game_location_tiles.locationTiles().fdel() //this line causes the error
def main():
the_game_play_controller = GamePlayController()
if __name__ == '__main__':
main()
只是尝试删除它作为使用 getter、setter、deleter 访问私有变量的测试。
【问题讨论】:
标签: python getter-setter