How to concatenate unicode strings ???

Ariel isaacrc82 at gmail.com
Tue Apr 26 12:22:36 EDT 2011


And what about if after the string is concat I want it to pass is to the
command line to do anything else, for instance:
one_command = cadena.decode('utf-8') + cadena1.decode('utf-8')
commands.getoutput(one_comand)
But I receive this error:
Traceback (most recent call last):
 File "<console>", line 1, in <module>
 File "/usr/lib/python2.6/commands.py", line 46, in getoutput
 return getstatusoutput(cmd)[1]
 File "/usr/lib/python2.6/commands.py", line 55, in getstatusoutput
 pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position
31: ordinal not in range(128)
How could I solve that ???
Regards
Ariel
On Tue, Apr 26, 2011 at 6:07 PM, Chris Rebert <clp2 at rebertia.com> wrote:
> 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 ???
>> That error is from the 2nd call to unicode(), not from the
> concatenation itself. Use proper Unicode string literals:
>> u'this an example language ' + u'español'
>> You'll probably also need to add the appropriate source file encoding
> declaration; see http://www.python.org/dev/peps/pep-0263/
>> Cheers,
> Chris
> --
> http://rebertia.com
>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110426/fe21fc7a/attachment-0001.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /