WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Problem with python-3.2 (solved)  (Read 17521 times)

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Problem with python-3.2 (solved)
« on: February 22, 2013, 07:24:45 PM »
Python3 default uses unicode but I can not seem to use accented characters and other non-ASCII characters.

From Aterm:
Code: [Select]
tc@box:~$ echo $LANG
it_IT.UTF-8

From the interpreter:
Code: [Select]
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)
>>>

trying to start source.py
Code: [Select]
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]
« Last Edit: April 03, 2013, 12:12:51 AM by vinnie »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11653
Re: Problem with python-3.2
« Reply #1 on: February 22, 2013, 09:07:38 PM »
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, ....
and also the answer that follows.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Problem with python-3.2
« Reply #2 on: February 23, 2013, 08:42:29 AM »
if I understood correctly:
Code: [Select]
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)
>>>

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11653
Re: Problem with python-3.2
« Reply #3 on: February 23, 2013, 09:06:56 AM »
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: [Select]
print("with \u00E0 non-ascii character".encode('utf-8'))

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Problem with python-3.2
« Reply #4 on: February 23, 2013, 09:57:40 AM »
Code: [Select]
>>> print("with \u00E0 non-ascii character".encode('utf-8'))
b'with \xc3\xa0 non-ascii character'

P.s. thanks rich for support

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Problem with python-3.2
« Reply #5 on: February 27, 2013, 06:47:55 AM »
my friend says that it is almost certainly system codify problem, where is this setting? I already use "kmap=qwerty/it" "lang=it_IT.UTF-8" boot code:




Code: [Select]
tc@box:~$ printenv
XPID=4453
E_CONF_PROFILE=001
USER=tc
E_ICON_THEME=Tango
HOME=/home/tc
E_LIB_DIR=/usr/local/lib
E_BIN_DIR=/usr/local/bin
PAGER=less -EM
PS1=\u@\h:\w\$
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-VdB62G288b,guid=b5cceafbd6dd1935a2a6ba66512deb4c
ENV=/home/tc/.ashrc
COLORTERM=rxvt
E_IPC_SOCKET=/tmp/enlightenment-tc@0000000000000000/disp-:0.0-4470
BACKUP=1
E_PREFIX=/usr/local
LOGNAME=tc
WINDOWID=31457282
COLORFGBG=15;0
TERM=rxvt
PATH=/usr/local/bin:/home/tc/.local/bin:/usr/local/sbin:/usr/local/bin:/apps/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/jre/bin:/etc/sysconfig/tcedir/ondemand:/usr/local/bin
G_FILENAME_ENCODING=iso8859-1
E_RESTART=1
DISPLAY=:0.0
DESKTOP_STARTUP_ID=E_START|5
LANG=it_IT.UTF-8
XAUTHORITY=/home/tc/.Xauthority
MANPAGER=less -isR
DESKTOP=Enlightenment-0.17.0
SHELL=/bin/sh
E_START=enlightenment_start
FLWM_TITLEBAR_COLOR=58:7D:AA
E_SCALE=1.500
E_LOCALE_DIR=/usr/local/share/locale
PANTS=ON
PWD=/home/tc
JAVA_HOME=/usr/local/java/jre
XDG_DATA_DIRS=/usr/local/share/enlightenment:/usr/local/share:/usr/local/share:/usr/share
E_DATA_DIR=/usr/local/share/enlightenment
E_START_TIME=1361963852.4
TZ=CET-1CEST,M3.5.0,M10.5.0/3
EDITOR=editor
« Last Edit: February 27, 2013, 06:50:44 AM by vinnie »

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Problem with python-3.2
« Reply #6 on: April 02, 2013, 11:47:59 PM »
I am continuing to look for solutions,
I found this:
Quote
System locale charset is ANSI_X3.4-1968
Your system's locale charset (i.e. the charset used to encode
filenames) is set to ANSI_X3.4-1968. It is highly unlikely that this
has been done intentionally. Most likely the locale is not set at all.
An invalid setting will result in problems when creating data
projects.
Solution: To properly set the locale charset make sure the LC_*
environment variables are set. Normally the distribution setup tools
take care of this.

Typed in terminal:
Code: [Select]
tc@box:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=it_IT.UTF-8
LC_CTYPE="it_IT.UTF-8"
LC_NUMERIC="it_IT.UTF-8"
LC_TIME="it_IT.UTF-8"
LC_COLLATE="it_IT.UTF-8"
LC_MONETARY="it_IT.UTF-8"
LC_MESSAGES="it_IT.UTF-8"
LC_PAPER="it_IT.UTF-8"
LC_NAME="it_IT.UTF-8"
LC_ADDRESS="it_IT.UTF-8"
LC_TELEPHONE="it_IT.UTF-8"
LC_MEASUREMENT="it_IT.UTF-8"
LC_IDENTIFICATION="it_IT.UTF-8"
LC_ALL=
tc@box:~$

Typed in python:
Code: [Select]
>>> import locale; locale.getlocale()
(None, None)

To my friend this command return  ('en_US', 'UTF-8')


Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Problem with python-3.2
« Reply #7 on: April 03, 2013, 12:12:29 AM »
Ok, i have been successful, i use getlocale.tcz to generate italian locale:

now in python:
Code: [Select]
>>> import locale; locale.getlocale()
('it_IT', 'UTF-8')

and in terminal I have no more error messages when I use the the comman "locale".