Reputation: 1129
I'm trying to export a python-chess game to a pgn file. The documentation recommends -
import chess
.
.
chessBoard = chess.Board()
.
.
#Play the game and when over do below
game = chess.pgn.Game.from_board(chessBoard)
with open('output.pgn', 'a') as the_file:
print(game, file=the_file, end="\n\n")
But the chess.pgn.Game.from_board(chessBoard)
line throws the below error -
AttributeError: module 'chess' has no attribute 'pgn'
pgn
shows up in intellisense as well when I type chess.
so the editor is also able to see that there is a pgn
in chess
. This is python 3.x running in VS2015 on windows 10.
What could be causing it?
Upvotes: 5
Views: 3818
Reputation: 173
For those of you who didn't get it to work with the accepted answer, check if you have named your file chess.py
(where you have written import chess
). If that's the case change it to something else, like pychess.py
.
The reason it doesn't work having your file named chess.py
is, I believe, that it's then essantially importing itself, and of course there is no chess.Board()
there.
Upvotes: 4
Reputation: 2930
To use the pgn
module you'd also have to do import chess.pgn
Upvotes: 7