This topic is READ ONLY
sandefan (39) [Avatar] Offline
#1
How can I get hangman to accept umlauts, such as 'ä' etc?

Hi,

To test whether I could use German words in hangman, I replaced the original file words.txt of hangman with a words.txt file containing only words with umlauts, such as 'ä', 'ö', 'ü'. When running hangman.py and entering, say 'ä', I get this error message:

Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/PythonCard/widget.py", line 408, in _dispatch
handler(background, aWxEvent)
File "hangman.py", line 109, in on_btnGuessLetter_mouseClick
if result.text in self.currentword:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(12smilie


I am using Hello World both with Windows XP and with Ubuntu-Linux. The error messages are the same.

How can I get hangman accepting umlauts and 'ß'? I would like to use German words, and they contain a lot of umlauts - and ß.

I have the English version of Hello World from http://www.manning.com/sande/, and dhe English edition of the book.

Thanks,

sandefan
sandefan (39) [Avatar] Offline
#2
Re: How can I get hangman to accept umlauts, such as 'ä' etc?
Ok, let me put forward this additional question:

There is a German edition of Hello World:

"Hello World! Programmieren für Kids und andere Anfänger. Mit CD [Broschiert].
Warren D. Sande (Autor), Carter Sande (Autor) "

Does anybody know whether they fixed this umlaut-Problem for the German edition?

cheers,

sandefan
warren.sande (211) [Avatar] Offline
#3
Re: How can I get hangman to accept umlauts, such as 'ä' etc?
Try this. Add the line:

import codecs

at the start of the program.

Then, in the on_initialize() function, change line

f=open("words.txt", 'r')

to

f = codecs.open("words.txt", encoding="utf-8")

You have to make sure the words.txt file is saved with UTF-8 encoding.

As far as the German version of the book, I don't think that was fixed. We (the authors) weren't even aware of the German translation until after it was published, so we had no opportunity to check or fix those sorts of things.


Warren Sande
sandefan (39) [Avatar] Offline
#4
Re: How can I get hangman to accept umlauts, such as 'ä' etc?
Thanks Warren, terrific! Your changes to the program did it smilie

Siggi

P.S.
As for the German edition, I saw it in a bookshop some time ago, but did not pay attention to 'hangman' - I preferred to get the English edition. However, there is one review on Amazon.de
http://www.amazon.de/product-reviews/3446421440/ref=sr_1_1_cm_cr_acr_txt?ie=UTF8&showViewpoints=1&qid=1289323804&sr=1-1
The reviewer "Dr. Gernot Starke www.arc42.de" is raving about your book. He and his son (about 10 years old) are more than happy with the programs.
sandefan (39) [Avatar] Offline
#5
Re: How can I get hangman to accept umlauts, such as 'ä' etc?
Just had a look into the German edition of "Hello World" on amazon.de. There seem to be no changes to hangman.py, such as this codecs thing for German umlauts smilie