python print next word in a file -
i have error on code here print next word/string contained on file
for in cursor.fetchall(): keywords.append(i[0]) open('qwer.txt','r') file: line in file: key in keywords: if key in line: line = line.split(". ") j in range(len(line)): <----error(str obj not callable) print line[key(j+1)] <----error
print line[key(j+1)]
is attempt call key
single argument j+1
. however, key
string can't called. think meant use index key[j+1]
, won't integer attempt index line
fail.
i think want is:
line[line.index(key) + 1]
really should checking key in line
after split:
with open('qwer.txt','r') file: line in file: line = line.split() key in keywords: if key in line: print line[line.index(key)+1]
Comments
Post a Comment