I am trying to read / count the character on the file (which is located in line 2)
all the even line of the file looks similar to this:
—————LL—NE–HVKTHTEEK—PF-ICTVCR-KS———-
here is my code so far but I got the error saying:
for character in len[(line2)]:
TypeError: ‘builtin_function_or_method’ object is not subscriptable
with open(filename) as f:
for line, line2 in itertools.izip_longest(f, f, fillvalue=''):
tokenizer=line.split()
print line, line2
print tokenizer[4]
for character in len[(line2)]:
print 't'
the problem is that
lenis a builtin function (len(mystring)returns an integer which is the number of characters in the string). You can’t subscript it (i.e. using square brackets with it will result in the TypeError you’ve referenced in your question). I’m not really sure what you’re trying to do here, maybe you want:or maybe you want:
From the comments, I’m still having a hard time picking up what you want, but I think you might want something like this: