0

I work with dictionary and I want to detect keys which contains non-english characters like 'č' for example.

This is my code:

for i in dictionaryMemory.keys():
            czechChars=['á','é','í','ó','ů','ě','ř','ť','č','š','ž']
            if any(s in i for s in czechChars):
                dictionaryMemory.pop(i)
                print(i)

But when I try to run this code, eclipse prints that SyntaxError: Non-ASCII character '\xc3' in file...

Ok, so I try to put # -*- coding: utf-8 -*-¨. It seems to work, but it can't find any of these characters. What to do?

EDIT: In the project properties I found this: Text file encoding: inherited from container(Cp1250)

I have a problems with encoding very usually but can't still figure out how to do it in a proper way...

3
  • 1
    Note that after adding # -*- coding: utf-8 -*- eclipse has a tendency to convert all non-ascii characters already in the file to ?. So make sure that after you add that, and save - they're not all deleted. Commented Jun 7, 2014 at 17:46
  • 1
    Change the coding comment from utf-8 to cp1250. Commented Jun 7, 2014 at 17:46
  • Thank you guys, both answers helped me!! Commented Jun 7, 2014 at 17:51

1 Answer 1

1

Like Tal Kremerman and Mark Ransom said, I tried to change the coding comment from utf-8 to cp1250 and then I checked, whether the chars in my code were in proper format, they did not so I changed them to č,š,ř... and finally it works!

Sign up to request clarification or add additional context in comments.

Comments

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.