Off-Topic > SCM EXtensions

Problem with python-3.2 (solved)

(1/2) > >>

vinnie:
Python3 default uses unicode but I can not seem to use accented characters and other non-ASCII characters.

From Aterm:

--- Code: ---tc@box:~$ echo $LANG
it_IT.UTF-8
--- End code ---

From the interpreter:

--- Code: ---tc@box:~$ python3
Python 3.2.2 (default, Jan 26 2012, 20:36:39)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(sys.stdout.encoding)
ANSI_X3.4-1968
>>> print (à)   
  File "<stdin>", line 0
   
    ^
SyntaxError: 'ascii' codec can't decode byte 0xe0 in position 7: ordinal not in range(128)
>>>
--- End code ---

trying to start source.py

--- Code: ---tc@box:~$ python3 ./stressed.py
Traceback (most recent call last):
  File "./stressed.py", line 1, in <module>
    print("this is a stressed character: \xe0")
UnicodeEncodeError: 'ascii' codec can't encode character '\xe0' in position 30: ordinal not in range(128)
tc@box:~$ [\code]
--- End code ---

Rich:
Hi vinnie
See if this provides any answers:
http://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20
Read the comment that begins with:

--- Quote ---In case someone else gets confused by this, I found a strange thing: my terminal uses utf-8, ....
--- End quote ---
and also the answer that follows.

vinnie:
if I understood correctly:

--- Code: ---tc@box:~$ python3
Python 3.2.2 (default, Jan 26 2012, 20:36:39)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("without non-ascii character".encode('utf-8'))
b'without non-ascii character'
>>> print("with à non-ascii character".encode('utf-8'))
  File "<stdin>", line 0
   
    ^
SyntaxError: 'ascii' codec can't decode byte 0xe0 in position 12: ordinal not in range(128)
>>>

--- End code ---

Rich:
Hi vinnie
I'm not familiar with Python, but that does look like what they are saying. Though, what happens if you do it  this way:

--- Code: ---print("with \u00E0 non-ascii character".encode('utf-8'))
--- End code ---

vinnie:

--- Code: --->>> print("with \u00E0 non-ascii character".encode('utf-8'))
b'with \xc3\xa0 non-ascii character'

--- End code ---

P.s. thanks rich for support

Navigation

[0] Message Index

[#] Next page

Go to full version