gpt4 book ai didi

python /杰森 : If substring in string always results in TypeError: string member test needs char left operand

转载 作者:太空宇宙 更新时间:2023-11-03 13:01:34 29 4
gpt4 key购买 nike

我有一个如下所示的列表:

wsadmin>print jvmLines
['', 'Stats name=jvmRuntimeModule, type=jvmRuntimeModule#', '{', 'name=HeapSize, ID=1, description=The total memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=BoundedRangeStatistic, lowWaterMark=1048576, highWaterMark=1048576, current=1048576, integral=0.0, lowerBound=1048576, upperBound=2097152', '', 'name=FreeMemory, ID=2, description=The free memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=CountStatistic, count=176789', '', 'name=UsedMemory, ID=3, description=The amount of used memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=CountStatistic, count=871786', '', 'name=UpTime, ID=4, description=The amount of time (in seconds) that the Java virtual machine has been running., unit=SECOND, type=CountStatistic, count=3809648', '', 'name=ProcessCpuUsage, ID=5, description=The CPU Usage (in percent) of the Java virtual machine., unit=N/A, type=CountStatistic, count=1', '}']

为什么会这样:

for line in jvmLines:
if "name=" in line:
print line

导致这个?

TypeError: string member test needs char left operand

如果我尝试 lambda 函数或 filter(),我也会得到同样的结果

最佳答案

试试find()方法

for line in jvmLines:
if line.find('name=') >= 0:
print line

关于 python /杰森 : If substring in string always results in TypeError: string member test needs char left operand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140003/

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