문제

I'm creating a small script to fetch heap memory usage from java-application server. I was able to connect and fetch the data well. However when I try to tidy the output a bit with re-library I get TypeError which confuses me.

TypeError: expected str or unicode but got <type 'javax.management.openmbean.CompositeDataSupport'>

My regex:

re.search(r'\=(.*)$', result)

I tested type of output:

type(result)

Which yields following:

<type 'javax.management.openmbean.CompositeDataSupport'>

Is there anyway I can convert the output to string? str(result) did not work.

도움이 되었습니까?

해결책

problem here:

type 'javax.management.openmbean.CompositeDataSupport'

result must be str. You can get string representation of CompositeDataSupport. It may be result.toString() or other method from here. Make some experiments with CompositeDataSupport methods.

UPD Note toString can return wrong result for your regexp if class author not overrided it from Object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top