【问题标题】:AttributeError: module 'chess' has no attribute 'Board' chess board errorAttributeError: module 'chess' has no attribute 'Board' 棋盘错误
【发布时间】:2021-12-12 03:41:22
【问题描述】:

我在 python 下国际象棋我遇到了这个错误

这是我的代码:

import chess.board

board=chess.Board()

board

完全错误:

Traceback (most recent call last):
  File "chess.py", line 1, in <module>
    import chess
  File "D:\Websites\repoting\chess.py", line 3, in <module>
    board=chess.Board()
AttributeError: module 'chess' has no attribute 'Board'

【问题讨论】:

  • 我没有安装这个模块,但是docs 说正确的语法是import chess 然后board = chess.Board()
  • 您保存代码的文件是否命名为chess.py?如果是这样,如果您更改此文件的名称,您会得到同样的错误吗?
  • 如果你发布这个答案我会选择你发布它

标签: python chess python-chess


【解决方案1】:

如果您是import chess,您可以使用chess.Board()。但是如果你import chess.Board 你只能使用Board()from 模块chess。我希望这会对您和所有阅读此答案的人有所帮助。

【讨论】:

    猜你喜欢
    • 2022-12-01
    • 2014-12-20
    • 2012-02-29
    • 2022-10-05
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 2023-01-02
    • 2022-08-04
    相关资源
    最近更新 更多