Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40436 > unrolled thread
| Started by | yomnasalah91@gmail.com |
|---|---|
| First post | 2013-03-04 01:37 -0800 |
| Last post | 2013-03-04 14:39 +0100 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
Encoding problem in python yomnasalah91@gmail.com - 2013-03-04 01:37 -0800
Re: Encoding problem in python Laszlo Nagy <gandalf@shopzeus.com> - 2013-03-04 10:57 +0100
Re: Encoding problem in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-04 10:18 +0000
Re: Encoding problem in python Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-03-04 14:39 +0100
| From | yomnasalah91@gmail.com |
|---|---|
| Date | 2013-03-04 01:37 -0800 |
| Subject | Encoding problem in python |
| Message-ID | <a70649cf-4b66-431f-bc97-e9af38b18e54@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| Date | 2013-03-04 10:57 +0100 |
| Message-ID | <mailman.2832.1362391640.2939.python-list@python.org> |
| In reply to | #40436 |
On 2013-03-04 10:37, yomnasalah91@gmail.com 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
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-03-04 10:18 +0000 |
| Message-ID | <513474f9$0$30001$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #40436 |
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
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
|---|---|
| Date | 2013-03-04 14:39 +0100 |
| Message-ID | <mailman.2838.1362404387.2939.python-list@python.org> |
| In reply to | #40436 |
2013/3/4 <yomnasalah91@gmail.com>: > 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? > -- > http://mail.python.org/mailman/listinfo/python-list Hi, I guess, you are using the built-in IDLE shell with python 2.7 and this is a specific limitation of its handling of some unicode characters (in some builds and OSes - "narrow"-unicode, Windows, most likely?) and its specific error message - not the usual python traceback mentioned in other posts). If it is viable, using python 3.3 instead would solve this problem for IDLE: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> w='العربى' >>> w 'العربى' (note the missing "u" in unicode literal before the starting quotation mark, which would be the usual usage in python 3, but python 3.3 also silently ignores u"..." for compatibility.) >>> w=u'العربى' >>> w 'العربى' >>> If python 2.7 is required, another shell is probably needed (unless I am missing some option to make IDLE work for this input); e.g. the following works in pyshell - part of the wxpython GUI library http://www.wxpython.org/ >>> w=u'العربى' >>> w u'\u0627\u0644\u0639\u0631\u0628\u0649' >>> print w العربى >>> hth, vbr
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web