Encoding problem in python

Y

yomnasalah91

I have a problem with encoding in python 27 shell.

when i write this in the python shell:

w=u'العربى'

It gives me the following error:

Unsupported characters in input

any help?
 
L

Laszlo Nagy

I have a problem with encoding in python 27 shell.

when i write this in the python shell:

w=u'العربى'

It gives me the following error:

Unsupported characters in input

any help?
Maybe it is not Python related. Did you get an exception? Can you send a
full traceback? I suspect that the error comes from your terminal, and
not Python. Please make sure that your terminal supports UTF-8 encoding.
Alternatively, try creating a file with this content:


# -*- encoding: UTF-8 -*-
w=u'العربى'

Save it as UTF-8 encoded file "test.py" (with an UTF-8 compatible
editor, for example Geany) and run it as a command:


python test.py

If it works then it is sure that the problem is with your terminal. It
will be an OS limitation, not Python's limitation.

Best,

Laszlo
 
S

Steven D'Aprano

I have a problem with encoding in python 27 shell.

when i write this in the python shell:

w=u'العربى'

It gives me the following error:

Unsupported characters in input

any help?

Firstly, please show the COMPLETE error, including the full traceback.
Python errors look like (for example):

py> x = ord(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ord() expected string of length 1, but int found


Copy and paste the complete traceback.


Secondly, please describe your environment:

- What operating system and version are you using? Linux, Windows, Mac
OS, something else? Which version or distro?

- Which console or terminal application? E.g. cmd.exe (Windows), konsole,
xterm, something else?

- Which shell? E.g. the standard Python interpreter, IDLE, bpython,
something else?


My guess is that this is not a Python problem, but an issue with your
console. You should always have your console set to use UTF-8, if
possible. I expect that your console is set to use a different encoding.
In that case, see if you can change it to UTF-8. For example, using Gnome
Terminal on Linux, I can do this:


py> w = u'العربى'
py> print w
العربى

and it works fine, but if I change the encoding to WINDOWS-1252 using the
"Set character encoding" menu command, the terminal will not allow me to
paste the string into the terminal.
 
E

electron

If you use Arabic frequently on your system, I suggest to change your
windows system locale from "Region and Language" in control panel
(Administrative tab) and set to Arabic.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top