user2729400
user2729400

Reputation: 71

Python coding problems (Utf-8, Hungarian language)

I wrote a script in Python 2 which is separated in 4-5 modules. I use the Hungarian language in the script, which contains several unusual characters like öüóőúéáűí. I wrote the modules on Win7 with an original cp-1250 coding, and then I moved to Ubuntu raring, where the system default is Utf-8.

First Tkinter left the spec. letter containing labels blank, which I managed to debug by setting every coding in the beginning of the modules to # -*- Utf-8 -*-.

Entries started to go mad too. Their .get() methods raised UnicodeDecodeError: 'ascii' codec can't decode byte...

And finally if for example module a.py had a dictionary dict = {'Sándor': 16} and module b.py has a line a.dict['Sándor'], it raises KeyError, as if dict didn't contain 'Sándor'. It doesn't do this with strings containing only normal characters, not does this with dictionaries of the module's own.

Upvotes: 1

Views: 2146

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799062

I wrote a script in python2... I use the Hungarian language in the script...

Did you use unicode literals? No, you did not. Rewrite your script to use and handle them properly.

{u'Sándor': 16}

Unicode In Python, Completely Demystified

Upvotes: 3

Related Questions