Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4059
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <akabaila@pcug.org.au> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '3.2': 0.07; 'ascii': 0.07; 'received:localnet': 0.07; 'python': 0.07; "'this": 0.09; 'everybody,': 0.09; 'url:dev': 0.09; 'url:peps': 0.09; 'pm,': 0.11; 'this:': 0.11; '>>>': 0.12; 'am,': 0.14; 'error:': 0.14; 'wrote:': 0.14; "'r')": 0.16; '46,': 0.16; '55,': 0.16; 'an:': 0.16; 'codec': 0.16; 'declaration;': 0.16; 'instance:': 0.16; 'literals:': 0.16; 'ordinal': 0.16; 'python3:': 0.16; 'rebert': 0.16; 'subject: ???': 0.16; 'subject:unicode': 0.16; 'url:pep-0263': 0.16; '"python': 0.16; 'traceback': 0.16; '(most': 0.16; 'command': 0.19; 'tue,': 0.20; 'cheers,': 0.20; 'language': 0.20; 'appropriate': 0.21; 'header:In-Reply-To:1': 0.22; 'itself.': 0.22; 'last):': 0.23; 'example': 0.24; 'byte': 0.25; 'extract': 0.25; 'ps:': 0.25; 'chris': 0.27; 'pass': 0.27; 'string': 0.29; 'error': 0.29; 'problem': 0.29; 'skip:" 30': 0.29; 'unicode': 0.29; 'probably': 0.30; 'least': 0.30; 'cc:addr:gmail.com': 0.31; 'charset:iso-8859-15': 0.31; 'cmd': 0.31; 'exist.': 0.31; 'unicode,': 0.31; 'wednesday': 0.31; 'does': 0.31; "can't": 0.31; 'perhaps': 0.32; 'to:addr:python-list': 0.32; 'source': 0.32; 'character': 0.33; 'computer,': 0.33; 'uses': 0.34; 'file': 0.35; 'characters': 0.35; 'problem,': 0.35; 'header :User-Agent:1': 0.35; '"",': 0.35; '???': 0.35; 'received:au': 0.36; 'url:python': 0.37; 'apr': 0.38; 'else,': 0.38; 'strings': 0.38; 'upgrading': 0.38; 'but': 0.38; 'languages': 0.38; 'url:org': 0.38; 'anything': 0.38; 'cc:2**1': 0.38; '8bit%:6': 0.39; 'url:au': 0.39; 'to:addr:python.org': 0.39; 'could': 0.39; 'how': 0.39; 'add': 0.39; 'works': 0.40; 'would': 0.40; '!!!': 0.60; 'header:Message-Id:1': 0.62; '2011': 0.62; 'limit': 0.62; 'spanish': 0.65; 'receive': 0.68; '26,': 0.68; 'concatenate': 0.84 |
| From | Algis Kabaila <akabaila@pcug.org.au> |
| Organization | PCUG - Users Helping Users |
| To | python-list@python.org |
| Subject | Re: How to concatenate unicode strings ??? |
| Date | Wed, 27 Apr 2011 04:03:29 +1000 |
| User-Agent | KMail/1.13.5 (Linux/2.6.35-25-generic-pae; KDE/4.5.1; i686; ; ) |
| References | <BANLkTikc5=6JLiWa447FuXm5riO=Hqdtnw@mail.gmail.com> <BANLkTindBznYOEibBn6XxkvDtDX3yetbxw@mail.gmail.com> <BANLkTiny1BnPfDQTnEJWfB3gr4ob-Lm4BQ@mail.gmail.com> |
| In-Reply-To | <BANLkTiny1BnPfDQTnEJWfB3gr4ob-Lm4BQ@mail.gmail.com> |
| MIME-Version | 1.0 |
| Content-Type | Text/Plain; charset="iso-8859-15" |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.854.1303841016.9059.python-list@python.org> (permalink) |
| Lines | 92 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1303841017 news.xs4all.nl 81474 [::ffff:82.94.164.166]:34580 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4059 |
Show key headers only | View raw
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 <isaacrc82@gmail.com>
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
<clp2@rebertia.com> wrote:
> >> 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 ???
> >>
> >> 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
Back to comp.lang.python | Previous | Next | Find similar
Re: How to concatenate unicode strings ??? Algis Kabaila <akabaila@pcug.org.au> - 2011-04-27 04:03 +1000
csiph-web