Я пытаюсь заставить эту программу работать, но сейчас у меня есть некоторые проблемы. Я хочу, чтобы этот код считывал общее количество слов в этом текстовом файле . Это то, что у меня есть на данный момент:
import os
openfile = input('Enter the input file: ')
accumulator = 0
accumulator2 = 0
accumulator3 = 0
accumulator4 = 0
word = 'PMID'
word2 = 'LA'
word3 = 'PT - Journal'
try:
file = open(openfile, 'r')
lines = file.readlines()
with open(openfile, 'r') as f:
lines = f.readlines()
for line in lines:
if word in line:
accumulator += 1
if word2 in line:
accumulator2 += 1
if word2 in line:
accumulator3 += 1
if 'Journal' in line and 'LA' in line:
accumulator4 += 1
print('there are:',accumulator ,'PMID')
print('there are:',accumulator2 ,'LA')
print('there are:',accumulator3 ,'PT')
print('there are:',accumulator4 ,'PT and LA')
exit()
except FileNotFoundError:
print('Input file not found.')
print('Please check the file name or the location of your input file.')
Я хочу, чтобы он также считал текстовые блоки, содержащие вместе «LA - eng» «PT - Journal article» как один (как третий блок). Есть ли способ сделать это, даже если они находятся в разных строках? Спасибо вам большое!