Search code examples
pythonchesspython-chessfen

How to get a string of the FEN position


After I do

import chess
board = chess.Board()

how can I have a string with the FEN of the position? In other words, how can I extract from board the FEN of the position as a string, with the same output as if I did

a='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'

?


Solution

  • You can use the fen function.

    board = chess.Board()
    a = board.fen()