0

I have a dictionary of Facebook group names and group id retreived from Facebook using graph API .

When I simply Print it using

for i in name:
  print i['name']

It prints all the group names even the ones in other languages such as Arabic and French.

but for this statement

check=raw_input("Want to post in %s?(Y/N)" % i['name'])

Group names with the non English Characters are not being printed. Why is this happening?

7
  • @Puciek Now it prints it but in the unicode form like \u5411\u464\564.How to get the charecters Commented Sep 17, 2013 at 10:32
  • What operating system? What is sys.getdefaultencoding()? Commented Sep 17, 2013 at 10:34
  • @LennartRegebro ubuntu 13.04 Commented Sep 17, 2013 at 10:34
  • What is repr(i['name'])? What is sys.getdefaultencoding()? Commented Sep 17, 2013 at 10:40
  • sys.getdefaultconfig() gives 'ascii' and print repr(i['name']) gives all the names but like u'\u5411\u464\u564' Commented Sep 17, 2013 at 11:02

1 Answer 1

1

"Want to post in %s?(Y/N)" is not Unicode.

Prefix it with a u:

u"Want to post in %s?(Y/N)" % i['name']

However, raw_input() doesn't like having Unicode text as the prompt. So you need to encode it with the encoding that your standard out uses.

prompt = u"Want to post in %s?(Y/N) " % i['name']
check = raw_input(prompt.encode(sys.stdout.encoding))
Sign up to request clarification or add additional context in comments.

3 Comments

I got the error UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-24: ordinal not in range(128)
@Stormvirux: Aha. Then the strings in the i dictionary is also not Unicode, so you are in fact not trying to print Unicode at all.
@Stormvirux: Absolutely not. You need to read up more about Unicode and encodings. Start here: regebro.wordpress.com/2011/03/23/… Then here: docs.python.org/2/howto/unicode.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.