Novice: replacing strings with unicode variables in a list
Diez B. Roggisch
deets at nospam.web.de
Wed Dec 6 04:40:33 EST 2006
aine_canby at yahoo.com wrote:
> Hi,
>
> Im totally new to Python so please bare with me.
>
> Data is entered into my program using the folling code -
>
> str = raw_input(command)
> words = str.split()
>
> for word in words:
> word = unicode(word,'latin-1')
> word.encode('utf8')
>
> This gives an error:
>
> File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
> return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in
> position 0
> : character maps to <undefined>
>
> but the following works.
>
> str = raw_input(command)
> words = str.split()
>
> for word in words:
> uni = u""
> uni = unicode(word,'latin-1')
> uni.encode('utf8')
This is the exact same code as the one above - there is no type declaration
in python, so your
uni = u''
statement is bollocks.
And I seriously doubt, that the above code and the above error message are
related - as you can see, the error is from cp850, a windows codepage. But
that isn't in the code above - so there must be something else happening.
Please provide the full script, and the desired input - then we might be
able to help you.
Diez
More information about the Python-list
mailing list