gpt4 book ai didi

python 国际象棋 - AttributeError : module 'chess' has no attribute 'pgn'

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:32 25 4
gpt4 key购买 nike

我正在尝试将 python 国际象棋游戏导出到 pgn 文件。 documentation推荐 -

import chess
.
.
chessBoard = chess.Board()
.
.
#Play the game and when over do below
game = chess.pgn.Game.from_board(chessBoard)
with open('output.pgn', 'a') as the_file:
print(game, file=the_file, end="\n\n")

但是 chess.pgn.Game.from_board(chessBoard) 行抛出以下错误 -

AttributeError: module 'chess' has no attribute 'pgn'

当我键入 chess. 时,

pgn 也会出现在 intellisense 中,因此编辑器也能够看到 pgn 国际象棋。这是在 Windows 10 上的 VS2015 中运行的 python 3.x。

可能是什么原因造成的?

最佳答案

要使用 pgn 模块,您还必须执行 import chess.pgn

关于 python 国际象棋 - AttributeError : module 'chess' has no attribute 'pgn' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42641603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com