Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
从你的帖子中,我推断你要么是编程新手,要么是Python新手,你可以自己做几件事来回答你的问题:请read the manual,特别是Python Tutorial部分。在本节中,您将了解实例化、__init__()的作用以及如何正确使用它。在
学习如何调试。许多类似于您的问题可以通过使用调试器来解决。Python ^{}是一个简单的调试器,它允许您逐行检查代码、设置断点、询问参数和变量以及在当前范围内执行任意代码以测试行为。在
通过删除多余的__init__,我能够从您的代码中获得所需的结果:>>> class GameState:
>>> board = []
>>> def __init__(self):
>>> self._player_turn = 'BLACK'
>>> self._valid_move = True
>>> columns = 4
>>> rows = 4
>>> def create_board(self, c, r):
>>> pass
>>>
>>> class OthelloGui:
>>> def __init__(self):
>>> pass
>>> def _create_circles(self, board):
>>> pass
>>> def run_othello(self):
>>> '''runs the game of othello'''
>>> a = GameState()
>>> a.create_board(a.columns, a.rows)
>>> print(a._valid_move)
>>> print a._player_turn
>>> self._create_circles(a.board)
>>>
>>> b = OthelloGui()
>>> b.run_othello()
True
BLACK
注意,我还向阅读我文章的人添加了额外的信息,比如所有方法的定义,这样就不会有关于我的代码实际做什么的问题了。希望这有帮助,祝你在编码冒险中好运,请下次尝试提高你在上面发布的问题的质量,你会得到更积极的答复。在