0

I have a utf8 file. When I read it's values python throws some exceptions so that I need to encode retrieved values. Then I save that value to redis, retrieve it later and store in another file. However I do not get to see nice file output that is readable. All "special" unicode characters come as e.g. Kj\xf8s or Kj\u00f8s

How can I fix this so that file becomes human readable :)

Thanks!

# pseudocode
file = codecs.open(filename,'r', 'utf-8')
for line in file:
  value = line.encode('utf-8')
  store_value_in_redis(value)

v = retrieve_value_from_redis()

file = codecs.open(filename2,'w', 'utf-8')

# Tried but did not help:
file.write(v)
file.write(v.decode('utf-8'))
Edijs Petersons
  • 537
  • 3
  • 6
  • 16
  • We store all our data in Redis in UTF-8. Redis does nothing with character encoding. Your Redis strings even may contain null characters. I'm not sure what you mean by 'human readable', if you display the redis data as UTF-8 when you store it as UTF-8, there should be no problem at all. – Tw Bert Apr 03 '15 at 10:59
  • File is created on windows, then sent to unix where python runs it saves in redis. Then another python reads it from redis and saves to file and sends that file back to windows. Somewhere I messed up encoding :) so that instead of seeing some letters like å i get something like what I mention in question. I tried the psuedocode on a lot smaller sample and it worked fine so I will need to look more at the details and as you mention there should be no problem. Thanks anyway! – Edijs Petersons Apr 03 '15 at 11:21
  • Ahh, the issue was related to JSON.dumps: http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence – Edijs Petersons Apr 03 '15 at 11:42

0 Answers0