0

Recently I encountered the following problem:

I have an array of strings:

name in ['Mueller', 'Meier', 'Schulze', 'Schmidt']

I face problems with its encoding in Python 3:

name.encode('cp1252')

Here is the full snippet:

 target_name = [name.encode('cp1252')
                         for name in
                         ['Mueller', 'Meier', 'Schulze', 'Schmidt']]
     assert_array_equal(arr['surname'],
                        target_name)

And here is the point where I also get the error. The error states:

Fail in test..... dtype='<|S7>'

I've been searching for a solution for some time, what I found so far is the need of changing the encoding. I applied:

name = np.char.encode('cp1252')

However I get another type of error with it.

Could someone help me with the error tracking?

Paul
  • 10,381
  • 13
  • 48
  • 86
  • Is indentation OK? – Ferit Mar 17 '16 at 23:30
  • Yes, totally fine, it looks only like this here, but indentation is good otherwise :) – Solarisfan Mar 17 '16 at 23:33
  • What is `arr['surname']`? Could we have it? – Bharel Mar 17 '16 at 23:36
  • It seems like problem is not about encoding. Is `assert_array_equal` from numpy? – Ferit Mar 17 '16 at 23:38
  • Exactly, assert_array_equal is from numpy. Here is the description :) self.arr = XRecArray.empty((4), dtype=dtype) ... self.arr.surname[:4] = [name.encode('cp1252') for name in ['Mueller', 'Meier', 'Schulze', 'Schmidt']] XRecArray is an array created for the purpose of the program and can be seen as a black-box :) – Solarisfan Mar 17 '16 at 23:43

0 Answers0