python导入类属性不存在_从另一个文件导入的Python类无法识别属性

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

注意,我还向阅读我文章的人添加了额外的信息,比如所有方法的定义,这样就不会有关于我的代码实际做什么的问题了。希望这有帮助,祝你在编码冒险中好运,请下次尝试提高你在上面发布的问题的质量,你会得到更积极的答复。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值