By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

raw_input encoding diferent from code encoding problem

al san
P: 2
Hello, everyone, any help wil be greatly appreciated.

I'm writing code for a japanese learning app in python;
so all my japanese strings have are preceeded by 'u' (eg. u'にほんご'); Everthing works like a charm, except for when I get input from the user.
Expand|Select|Wrap|Line Numbers
  1. >>> internal=[u'\u306f\u3057\u3063\u305f', u'\u306f\u3057\u3063\u3066', u'\u306f\u3057\u3089\u306a\u3044', u'\u306f\u3057\u308a\u307e\u3059', u'\u306f\u3057\u308b', u'\u306f\u3057\u308c', u'\u306f\u3057\u308d\u3046']
  2. >>> user_input=['\x82\xcd\x82\xb5\x82\xc1\x82\xbd', '\x82\xcd\x82\xb5\x82\xc1\x82\xc4', '\x82\xcd\x82\xb5\x82\xe7\x82\xc8\x82\xa2', '\x82\xcd\x82\xb5\x82\xe8\x82\xdc\x82\xb7', '\x82\xcd\x82\xb5\x82\xe9', '\x82\xcd\x82\xb5\x82\xea', '\x82\xcd\x82\xb5\x82\xeb\x82\xa4']
  3. >>> for i in range (len(internal)):
  4.     print "code data: %s" % internal[i]
  5.     print "raw_input: %s" % user_input[i]
  7. code data: はしった
  8. raw_input: はしった
  9. code data: はしって
  10. raw_input: はしって
  11. code data: はしらない
  12. raw_input: はしらない
  13. code data: はしります
  14. raw_input: はしります
  15. code data: はしる
  16. raw_input: はしる
  17. code data: はしれ
  18. raw_input: はしれ
  19. code data: はしろう
  20. raw_input: はしろう
  21. >>> 
As you can see, on the screen the text looks the same, but, behind the scenes the two encodings are totally different from eachother.
Why is this an issue?
Well, because I need to compare the two texts(raw_input vs program data) and if they
look the same on the screen, then I need the result to be True not False...

Thank you for your time.
Dec 10 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.