Reputation: 111
I have some code that generates some a start and end position using string.find.
I then substring the string using the string positions.
The code fails with indices must be integers.
Just to make sure they are integers, I have cast them.
Here's the code snippet with a print to show the values:
print("s={0} e={1}".format(s, e))
grab=source[int(s), int(e)]
and here's the output:
s=7478 e=7690
Exception "unhandled TypeError"
string indices must be integers
I'm obviously missing something but I have no idea what.
Any ideas anyone?
Upvotes: 0
Views: 93
Reputation: 71522
You've used a Tuple[int, int]
as the index instead of an int
. You probably meant to use the slice notation, which uses a :
instead of a ,
:
source[int(s):int(e)]
Upvotes: 1