niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.4k stars 521 forks source link

module 'chess.pgn' has no attribute 'tell' #1101

Closed JavierYepez closed 1 month ago

JavierYepez commented 1 month ago

Hi, Im having a problem with the PGN module. This code gives me an error telling that tell() attribute doesn't exists.

AttributeError: module 'chess.pgn' has no attribute 'tell'

import chess
import chess.pgn

with open(test, 'r') as pgn_file:
    while True:
        offset = chess.pgn.tell()
        game = chess.pgn.read_headers(pgn_file)
        if not game:
            break

But this code works fine which means that the PGN module is imported:

import chess
import chess.pgn

with open(test, 'r') as pgn_file:
    while True:
        # offset = chess.pgn.tell()
        game = chess.pgn.read_headers(pgn_file)
        if not game:
            break

UPDATE The only functions available are: skip_game(handle: TextIO) -> bool read_headers(handle: TextIO) -> Optional[Headers] read_game(handle: TextIO) -> Optional[Game]

Library: chess 1.10.0 pyhd8ed1ab_1 conda-forge

niklasf commented 1 month ago

In the example, pgn refers to a file object, as in:

pgn = open("data/pgn/kasparov-deep-blue-1997.pgn")
JavierYepez commented 1 month ago

You are absolutely right. I'm a bit blind. Thank you