Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4051

Re: How to concatenate unicode strings ???

References <BANLkTikc5=6JLiWa447FuXm5riO=Hqdtnw@mail.gmail.com>
Date 2011-04-26 09:12 -0700
Subject Re: How to concatenate unicode strings ???
From Dan Stromberg <drsalists@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.843.1303834332.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Apr 26, 2011 at 8:58 AM, Ariel <isaacrc82@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'
>>>

Back to comp.lang.python | Previous | Next | Find similar


Thread

Re: How to concatenate unicode strings ??? Dan Stromberg <drsalists@gmail.com> - 2011-04-26 09:12 -0700

csiph-web