0

I've been working on project in python chess playing with lichess opening explorer API. I have succeeded in doing all the hard work and finally got the PGN tree that I wanted but when I try to export my PGN tree to a text file all I am left with is empty file.

I was trying to export my PGN file using a method proposed in the docs: https://python-chess.readthedocs.io/en/latest/pgn.html#chess.pgn.FileExporter but It doesn't work. Here is some of my code:

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)
Oli
  • 2,507
  • 1
  • 11
  • 23

1 Answers1

0

Embarrassing, this block of code is performed in a loop. I should have waited until the script end. Everything works fine.