Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Jython: If substring in string always results in TypeError: string member test needs char left operand

I have a list that looks like this:

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', '}']

Why does this:

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

Lead to this?

TypeError: string member test needs char left operand

I also get the same if I try lambda functions or a filter()

like image 924
Seer Avatar asked Jan 12 '23 05:01

Seer


1 Answers

try the find() method

for line in jvmLines:
    if line.find('name=') >= 0:
        print line
like image 180
sas Avatar answered Jan 30 '23 08:01

sas