0

I tried to apply str to an array of objects however that gives me the known encoding error "can't convert... to string". Should I use unicode at that point?

AME
  • 2,499
  • 5
  • 29
  • 45
  • 1
    What's the array of objects? – Volatility Feb 04 '13 at 09:26
  • You need to give much more details. What are you *doing* with the list? Did you read the [Python Unicode HOWTO](http://docs.python.org/2/howto/unicode.html) at all? – Martijn Pieters Feb 04 '13 at 09:29
  • 1
    Unlikely. `str` doesn't care what encoding it contains, it's just a byte array. My guess is the error message means simply that there was a problem calling `__str__()` or some such. (Assuming Python 2.x. On Python 3.x it *might* be a unicode encoding error, but then again on Python 3.x `str` is what used to be `unicode` so your proposed solution doesn't apply anyway, and it's impossible tell what's going on without more diagnosis on your part.) – millimoose Feb 04 '13 at 09:29
  • @millimoose: excellent, that was the problem. – AME Feb 04 '13 at 09:31
  • @AME Methodical aside: your question manifests a textbook example of the XY problem. Instead of diagnosing and describing your actual situation you jumped ahead and assumed what the explanation is and asked about a solution to a problem you didn't have in the first place. It's a great way to get closed as "too localized". – millimoose Feb 04 '13 at 09:34
  • thank you for explaining. The information "str doesn't care" was very helpful. – AME Feb 04 '13 at 09:40
  • Interesting: str(u"×") raises an Error. – AME Feb 04 '13 at 09:48

0 Answers0