Encoding problem in python

Discussion in 'Python' started by yomnasalah91@gmail.com, Mar 4, 2013.

  1. Guest

    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?
    , Mar 4, 2013
    #1
    1. Advertising

  2. Laszlo Nagy Guest

    On 2013-03-04 10:37, 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
    Laszlo Nagy, Mar 4, 2013
    #2
    1. Advertising

  3. 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
    Steven D'Aprano, Mar 4, 2013
    #3
  4. electron Guest

    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.
    electron, Aug 22, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    18,796
    Jon Skeet [C# MVP]
    Jun 9, 2004
  2. Replies:
    1
    Views:
    23,312
    Real Gagnon
    Oct 8, 2004
  3. Gabriel Rossetti
    Replies:
    2
    Views:
    417
    Gabriel Rossetti
    Feb 18, 2009
  4. Greg
    Replies:
    9
    Views:
    807
    Nobody
    Oct 8, 2011
  5. Replies:
    2
    Views:
    352
Loading...

Share This Page