Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Encoding problem in python

Reply
Thread Tools

Encoding problem in python

 
 
yomnasalah91@gmail.com
Guest
Posts: n/a
 
      03-04-2013
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?
 
Reply With Quote
 
 
 
 
Laszlo Nagy
Guest
Posts: n/a
 
      03-04-2013
On 2013-03-04 10:37, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      03-04-2013
On Mon, 04 Mar 2013 01:37:42 -0800, yomnasalah91 wrote:

> 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.



--
Steven
 
Reply With Quote
 
electron
Guest
Posts: n/a
 
      08-22-2013
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
encoding problem with BeautifulSoup - problem when writing parsedtext to file Greg Python 9 10-08-2011 03:30 PM
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
Python/environment problem with char encoding/decoding Gabriel Rossetti Python 2 02-18-2009 02:24 PM
changing JVM encoding; setting -Dfile.encoding doesn't work pasmol@plusnet.pl Java 1 10-08-2004 09:50 PM
Encoding.Default and Encoding.UTF8 Hardy Wang ASP .Net 5 06-09-2004 04:04 PM



Advertisments