有人能告诉我这段代码出了什么问题吗?我不断得到字符串索引,必须是整数,我已经尝试了我能想到的所有方法。它实际上在一个if语句中,但我将其简化为以下内容,以查看是否能找到问题所在。对于我正在搜索的字符串,Find将返回23。我添加了int函数,看看是否可以修复它。
stringloc = 1
stringloc = text.find('http')
print(stringloc)
print(text[0, int(stringloc)])
下面是返回消息print(text0,int( string the )) TypeError:字符串索引必须是整数
发布于 2018-03-23 06:17:20
您可能希望使用像start:end这样索引
In [1]: text="this is the text for demo"
In [2]: stringloc=text.find('text')
In [3]: stringloc
Out[3]: 12
In [4]: print(text[0:stringloc])
this is the
在5年内
https://stackoverflow.com/questions/49440140
复制