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

标签 python string list filter jython

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

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/

相关文章:

java - StringBuffer 和 String 的区别

list - 数学: adding a list of lists elementwise

python - 面试准备 : optimizing swapLexOrder

python - 如何使用 Flask 渲染模板并同时发送文件

python - Selenium GeckoDriver 启动 Firefox 浏览器的速度很慢

python - "File too short"与 Tableau 数据提取 API(Python 和 Linux)

德尔菲字符串: Pull a last name from a full name

string - 找到一种将所有大写字母放在小写字母后面且相对顺序不变的算法

c - C中struct的双指针是什么意思

python - 计算 Python 列表中真正 boolean 值的数量