python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

Getting ChildNode value???

Open oayk23 opened this issue 8 months ago • 0 comments

Hello, i have a .pgn file which includes moves with comments. I want to extract the moves and the comments in the pgn games. for example: (some headers) [event..]....

1.e4{this may leads to italian} e5 2.{ some comments... etc.}

i want to extract: "1.e4{this may leads to italian} e5 2.{ some comments... etc.}" this part.

following code:

pg = open("ChessAdmin annotated games.pgn")
game_list = []
while True:
    game = pgn.read_game(pg)
    if game is None:
        break
    mainline = game.game()
    for move in mainline:
        game_list.append(move)
        

leads something like this:

[<ChildNode at 0x1b931a4b590 (1. e4 ...)>,
 <ChildNode at 0x1b9377ad430 (1. c4 ...)>,
 <ChildNode at 0x1b9377af410 (1. c4 ...)>,
 <ChildNode at 0x1b9377bfe00 (1. d4 ...)>,
 <ChildNode at 0x1b9377afc20 (1. c4 ...)>,
 <ChildNode at 0x1b93784a6f0 (1. d4 ...)>,
 <ChildNode at 0x1b9377bce00 (1. c4 ...)>,
 <ChildNode at 0x1b93784e870 (1. c4 ...)>,
 <ChildNode at 0x1b93786b770 (1. e4 ...)>,
 <ChildNode at 0x1b93786ae40 (1. c4 ...)>,
 <ChildNode at 0x1b9377ade20 (1. e4 ...)>,
 <ChildNode at 0x1b93787b9e0 (1. c4 ...)>,
 <ChildNode at 0x1b93797d7f0 (1. c4 ...)>,
 <ChildNode at 0x1b937980ef0 (1. c4 ...)>,
 <ChildNode at 0x1b937986ba0 (1. c4 ...)>,

When i printing this move in for move in mainline: i get the desired output. but i want to extract it programmatically and save it to my database. How can i do this? Could you help me with this?

oayk23 avatar Apr 09 '25 19:04 oayk23