gpt4 book ai didi

python字符串操作,在字符串中查找子字符串

转载 作者:行者123 更新时间:2023-12-02 04:37:56 25 4
gpt4 key购买 nike

<分区>

我正在尝试在 python 中的较大字符串中查找子字符串。我试图在找到字符串“Requests per second:”后找到文本。看来我缺乏对 python 字符串和 python 的一般知识。

我的错误出现在代码 minusStuffBeforeReqPer = output[reqPerIndx[0], len(output)] 的第 3 行,我得到的错误是没有 [0] 在 reqPerIndx 上,我试图访问一个元组,但是我得到了一个错误,即我 int object has no attribute __getitem__。我试图在 output 字符串中找到 reqPerStr 开头的索引。

代码

#output contains the string reqPerStr.
reqPerStr = "Requests per second:"
reqPerIndx = output.find(reqPerStr)
minusStuffBeforeReqPer = output[reqPerIndx[0], len(output)]
eolIndx = minusStuffBeforeReqPer.find("\n")
semiColIndx = minusStuffBeforeReqPer.find(":")
instanceTestObj.reqPerSec = minusStuffBeforeReqPer[semiColIndx+1, eolIndx]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com