0

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.

4

1 回答 1

0

这里的问题:

type 'javax.management.openmbean.CompositeDataSupport'

result必须是str。您可以获得CompositeDataSupport. 它可能是从这里result.toString()或其他方法。用方法做一些实验。CompositeDataSupport

如果类作者没有从 Object 覆盖它, UPD NotetoString可能会为您的正则表达式返回错误的结果。

于 2013-11-13T10:18:01.403 回答