@anysofronova

Из-за чего может быть ошибка «'str' object is not callable»?

from tokenize import tokenize

input_file = 'ALL.txt'
output_file = 'ALL1.txt'
MULTI_WORD = -1
word_locations = {}

for pos, word in tokenize(input_file):
    if word not in word_locations:
        word_locations[word] = pos
    else:
        word_locations[word] = MULTI_WORD
        
edit_points = [(pos, len(word)) for word, pos in word_locations.iteritems()
                                if pos != MULTI_WORD]

start_pos = 0
for end_pos, edit_length in edit_points:
    input_file.seek(start_pos)
    output_file.write(input_file.read(end_pos - start_pos))
    start_pos = end_pos + edit_length
input_file.seek(start_pos)
output_file.write(input_file.read())


В строке for pos, word in tokenize(input_file): появляется ошибка 'str' object is not callable
  • Вопрос задан
  • 938 просмотров
Пригласить эксперта
Ответы на вопрос 1
planc
@planc
input_file должен быть файлом, а не строкой


tokenize.open(filename)


https://docs.python.org/3/library/tokenize.html
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы