Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to concatenate unicode strings ???

Reply
Thread Tools

Re: How to concatenate unicode strings ???

 
 
Algis Kabaila
Guest
Posts: n/a
 
      04-26-2011
On Wednesday 27 April 2011 02:33:00 Ariel wrote:
> with commands.getoutput(one_comand.encode('utf-8')) it works
> !!!
>
> On Tue, Apr 26, 2011 at 6:22 PM, Ariel <(E-Mail Removed)>

wrote:
> > 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(12
> >
> > How could I solve that ???
> > Regards
> > Ariel
> >
> > On Tue, Apr 26, 2011 at 6:07 PM, Chris Rebert

<(E-Mail Removed)> wrote:
> >> On Tue, Apr 26, 2011 at 8:58 AM, Ariel

<(E-Mail Removed)> 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(12
> >> >
> >> > 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

The following is from Idle3 (IDLE for Python3:

>>> 'this an example language ' + 'espaņol'

'this an example language espaņol'
>>>


In Python3 all strings are unicode, so your problem just does
not exist. Upgrading to Python 3 would eliminate the problem,
as the above extract demonstrates.

Perhaps it is time to upgrade to Python 3.2

In the above when I write Python 3, I mean "Python 3.1 or
higher".

With kind regards,

OldAl.

PS: I do not have Spanish on my computer, but I do have at least
one other languages that uses characters that are outside of
ascii limit of 128.
A.
--
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Concatenate/De-Concatenate Carlos VHDL 10 10-24-2012 01:04 PM
helper lib to create (concatenate) sql query strings? szczepiq@gmail.com Java 0 10-23-2005 03:00 PM
How to concatenate strings that contains has nulls? jt C Programming 13 09-28-2005 09:21 PM
concatenate strings Lars Tackmann C Programming 3 12-31-2003 12:51 PM



Advertisments