Re: How to concatenate unicode strings ???

2011-04-26 Thread Algis Kabaila
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 "", line 1, in 
> >   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 "", line 1, in 
> >> > 
> >> > 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Terry Reedy

On 4/26/2011 12: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 "", line 1, in
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/


Or use Python 3

--
Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Jean-Michel Pichavant

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 "", line 1, in 
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
  

an example of shebang

#!/usr/bin/python
# -*- coding: utf-8 -*-


that should allow you to write u'español' in your code.

JM
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Ariel
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 "", line 1, in 
>   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 "", line 1, in 
>> > 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
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Albert Hopkins
On Tue, 2011-04-26 at 17:58 +0200, 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 "", line 1, in 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 11: ordinal not in range(128)
> 
> How could I concatenate unicode strings ???
> 
Your problem isn't with concationation. Your problem is with:


unicode('español')


That is your are passing a non-unicode string to the unicode type and,
it seems the default encoding on your system is ASCII, but "ñ"
is not valid ASCII encoding.

So you can do one of two things:

* Use a unicode literal, e.g. u'español'
* pass whatever encoding you are actually using in your byte string,
  e.g. unicode('español', 'utf8')

If you are writing this in a module and you want to use unicode
literals, you should put something similar at the top of the file:

# -*- encoding: utf-8 -*-

HTH,
-a


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Ariel
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 "", line 1, in 
  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 "", line 1, in 
> > 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
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Dan Stromberg
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 "", line 1, in 
> 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 "", line 1, in 
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'
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate unicode strings ???

2011-04-26 Thread Chris Rebert
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 "", line 1, in 
> 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
-- 
http://mail.python.org/mailman/listinfo/python-list


How to concatenate unicode strings ???

2011-04-26 Thread Ariel
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 "", line 1, in 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 11:
ordinal not in range(128)

How could I concatenate unicode strings ???

Regards
Thanks in advance.
Ariel
-- 
http://mail.python.org/mailman/listinfo/python-list