pythonpython-2.7qtsquish

How to work 'Object' type variable with special character as string?


I am doing some testing of a text UI element from a Qt application. It has a special character in it. When I try to get the text with Squish the received value type is Object. The final goal is to do some operations on it like printing it out or comparing it with another string. It's also completely fine to rid of the special character and only look at the remaining value.

In an effort to find out what I can do with this value, I've tried the following:

  1. value.split('')

    SyntaxError: Ambiguous overload 'split(str)'. Candidates: QString::split(const QString & sep) QString::split(QChar sep)

  2. str(value)

    UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 2: ordinal not in range(128)

  3. value.encode('utf-8')

    AttributeError: Object does not have any properties

  4. unicode(value, error='replace')

    TypeError: coercing to Unicode: need string or buffer, Object found

Usually in other case I can use str() fine since there is no special character. This is from Python 2, and upgrading is not really an option since it's quite a big project and takes time. Please give me some suggestion if this can be done in anyway. Thank you.


Solution

  • So using dir() on that value I find out that QString function can be used. After some more experimenting I find QString &QString::replace(int position, int n, const QChar *unicode, int size) as the only method that I can use without running into error Ambiguous overload. Then just replacing the special character away and use the remaining value.