Python chess FileExporter 和 open() 函数不导出游戏



我一直致力于python国际象棋项目,使用开放资源管理器API。我已经成功地完成了所有的艰苦工作,最终得到了我想要的PGN树,但是当我试图将我的PGN树导出到一个文本文件时,我只剩下一个空文件。

我试图使用在文档中提出的方法导出我的PGN文件:https://python-chess.readthedocs.io/en/latest/pgn.html#chess.pgn.FileExporter但它不起作用。下面是我的一些代码:

start = df.Setup()
start.starting_position = variation
board = chess.Board(fen=start.starting_position)
study = chess.pgn.Game()
study.setup(board)
# Get the main line and primary branches
mainline_and_friends(study)
#Here I am using method proposed in the docs and left with empty file in PGN folder
new_pgn = open(f"PGN/Italian game Evans gambit {counter}", "w", encoding="utf-8")
exporter = chess.pgn.FileExporter(new_pgn)
study.accept(exporter)

令人尴尬的是,这段代码是在循环中执行的。我应该等到剧本结束。一切正常

相关内容

最新更新