【发布时间】:2015-04-03 05:35:31
【问题描述】:
我正在做一个作业,这是班级的样子:
class GameStateNode:
'''
A tree of possible states for a two-player, sequential move, zero-sum,
perfect-information game.
value: GameState -- the game state at the root of this tree
children: list -- all possible game states that can be reached from this
game state via one legal move in the game. children is None until grow
is called.
'''
def __init__(self, game_state):
''' (GameStateNode, GameState) -> NoneType
Initialize a new game state tree consisting of a single root node
that contains game_state.
'''
self.value = game_state
self.children = []
然后我写了这两个函数,因为我需要一个递归的 str:
def __str__(self):
''' (GameStateNode) -> str '''
return _str(self)
def _str(node):
''' (GameStateNode, str) -> str '''
return ((str(node.value) + '\n') +
((str(child) for child in node.children) if node.children else ''))
谁能告诉我我的 _str 函数有什么问题?
【问题讨论】:
标签: python string generator typeerror