Games are represented as a tree of moves. Each GameNode can have extra information such as comments. The root node of a game (Game extends GameNode) also holds general information, such as game headers.
chess.pgn.Game
chess.pgn.GameNode
chess.pgn.read_game
chess.pgn.scan_headers
chess.pgn.scan_offsets
If you want to export your game game with all headers, comments and variations you can use:
>>> print(game) [Event "?"] [Site "?"] [Date "????.??.??"] [Round "?"] [White "?"] [Black "?"] [Result ""] <BLANKLINE> 1. e4 e5 { Comment }
Remember that games in files should be separated with extra blank lines.
>>> print(game, file=handle, end="nn")
Use exporter objects if you need more control. Exporter objects are used to allow extensible formatting of PGN like data.
chess.pgn.StringExporter
chess.pgn.FileExporter
Numeric anotation glyphs describe moves and positions using standardized codes that are understood by many chess programs. During PGN parsing, annotations like !, ?, !!, etc. are also converted to NAGs.