Re: How to concatenate unicode strings ???

Discussion in 'Python' started by Algis Kabaila, Apr 26, 2011.

  1. 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 <>

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

    <> wrote:
    > >> On Tue, Apr 26, 2011 at 8:58 AM, Ariel

    <> 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

    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
    Algis Kabaila, Apr 26, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    713
  2. Lars Tackmann

    concatenate strings

    Lars Tackmann, Dec 30, 2003, in forum: C Programming
    Replies:
    3
    Views:
    708
    Stefan Farfeleder
    Dec 31, 2003
  3. jt
    Replies:
    13
    Views:
    717
    Gregory Pietsch
    Sep 28, 2005
  4. Mr. Ken
    Replies:
    5
    Views:
    957
    Rolf Magnus
    Jul 24, 2006
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    848
Loading...

Share This Page