Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top