0

I want to search through a text file and output substrings that match the user input, but when my program searches each line I want it to only search the characters between the "|" character and the end of the line. But I keep getting the following error:

Tim
  • 191
  • 2
  • 28
  • You should use a context manager to handle files. Are you using Python 2? – AMC Jan 29 '20 at 05:32
  • Does this answer your question? [Why am I seeing "TypeError: string indices must be integers"?](https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers) – AMC Jan 29 '20 at 05:33

1 Answers1

1

You should use slices. Just replace , with : in your code:

y = line[char_pos:x]
neverwalkaloner
  • 46,181
  • 7
  • 92
  • 100