Conditional for...in failing with utf-8, Spanish book translation
hbloftis at uncc.edu
Mon Apr 21 08:33:47 CEST 2008
This is my first Usenet post!
I've run into a wall with my first Python program. I'm writing some
simple code to take a text file that's utf-8 and in Spanish and to use
online translation tools to convert it, word-by-word, into English. Then
I'm generating a PDF with both of the languages.
Most of this is working great, but I get intermittent errors of the form:
tw returned now
iconv: illegal input sequence at position 0
tw returned error: the required parameter "srctext" is missing
English: error: the required parameter "srctext" is missing
The output should look like:
tw returned englishtranslation
I've narrowed the problem down to a simple test program. Check this out:
# -*- coding: utf-8 -*-
acceptable = "abcdefghijklmnopqrstuvwxyzóíñú" # this line will work
acceptable = "abcdefghijklmnopqrstuvwxyzóíñúá" # this line won't
word = "¡A"
word_key = ''.join([c for c in word.lower() if c in acceptable])
print "word_key = " + word_key
Any ideas? I'm really stumped!
More information about the Python-list