How to concatenate unicode strings ???

Dan Stromberg drsalists at gmail.com
Tue Apr 26 12:12:09 EDT 2011


On Tue, Apr 26, 2011 at 8:58 AM, Ariel <isaacrc82 at gmail.com> wrote:
> Hi everybody, how could I concatenate unicode strings ???
> What I want to do is this:
>
> unicode('this an example language ') + unicode('español')
>
> but I get an:
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 11:
> ordinal not in range(128)
>
> How could I concatenate unicode strings ???

I believe it's not the catenation, but rather the second of two
unicode() invocations getting an invalid character for the default
encoding:

$ /usr/local/cpython-2.7/bin/python
cmd started 2011 Tue Apr 26 09:10:22 AM
Python 2.7 (r27:82500, Aug  2 2010, 19:15:05)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode('this an example language ') + unicode('español')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
4: ordinal not in range(128)
>>> unicode('this an example language ') + unicode('español', 'latin-1')
u'this an example language espa\xc3\xb1ol'
>>>



More information about the Python-list mailing list