FAQ
I am developing a little program in Mac with wxPython.
But I have problems with the characters that are not in ASCII. Like
some special characters in French or Turkish.
So I am looking for a way to solve this. Like an encoding standard
that supports all languages. Or some other way.

Thanks
Ata Jafari

Search Discussions

  • Thomas Jollans at Aug 17, 2010 at 8:55 pm

    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython.
    But I have problems with the characters that are not in ASCII. Like
    some special characters in French or Turkish.
    So I am looking for a way to solve this. Like an encoding standard
    that supports all languages. Or some other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text is
    mostly Latin, then just go for UTF-8, if you use other alphabets extensively,
    you might want to consider UTF-16, which might the use a little less space.
  • Ata.jaf at Aug 19, 2010 at 8:29 am

    On Aug 17, 11:55?pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython.
    But I have problems with the characters that are not in ASCII. Like
    some special characters in French or Turkish.
    So I am looking for a way to solve this. Like an encoding standard
    that supports all languages. Or some other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text is
    mostly Latin, then just go for UTF-8, if you use other alphabets extensively,
    you might want to consider UTF-16, which might the use a little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?". But I see that in GUI this character is replaced
    with another strange characters. I mean it doesn't work.
    And when I try to use UTF-16, I get an syntax error that declares
    "UTF-16 stream does not start with BOM".
  • Steven D'Aprano at Aug 19, 2010 at 8:48 am

    On Thu, 19 Aug 2010 01:29:51 -0700, ata.jaf wrote:
    On Aug 17, 11:55?pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython. But I have
    problems with the characters that are not in ASCII. Like some special
    characters in French or Turkish. So I am looking for a way to solve
    this. Like an encoding standard that supports all languages. Or some
    other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text
    is mostly Latin, then just go for UTF-8, if you use other alphabets
    extensively, you might want to consider UTF-16, which might the use a
    little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code

    Do you have a source code encoding line at the start of your script?


    http://www.python.org/dev/peps/pep-0263/

    and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?". But I see that in GUI this character is replaced
    with another strange characters. I mean it doesn't work. And when I try
    to use UTF-16, I get an syntax error that declares "UTF-16 stream does
    not start with BOM".

    What GUI are you using?


    Please COPY AND PASTE (do not retype) the EXACT error message you get,
    including the entire traceback.




    --
    Steven
  • Ata.jaf at Aug 20, 2010 at 3:02 pm

    On Aug 19, 11:48?am, Steven D'Aprano <steve-REMOVE- T... at cybersource.com.au> wrote:
    On Thu, 19 Aug 2010 01:29:51 -0700, ata.jaf wrote:
    On Aug 17, 11:55?pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython. But I have
    problems with the characters that are not in ASCII. Like some special
    characters in French or Turkish. So I am looking for a way to solve
    this. Like an encoding standard that supports all languages. Or some
    other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text
    is mostly Latin, then just go for UTF-8, if you use other alphabets
    extensively, you might want to consider UTF-16, which might the use a
    little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code
    Do you have a source code encoding line at the start of your script?

    http://www.python.org/dev/peps/pep-0263/
    and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?". But I see that in GUI this character is replaced
    with another strange characters. I mean it doesn't work. And when I try
    to use UTF-16, I get an syntax error that declares "UTF-16 stream does
    not start with BOM".
    What GUI are you using?

    Please COPY AND PASTE (do not retype) the EXACT error message you get,
    including the entire traceback.

    --
    Steven
    Yes I have a source code encoding line.
    Here it is:


    # -*- coding: utf_16 -*-


    I am using WxPython.

    And the error that I get about using utf-16 is:\



    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "z.py", line 2
    SyntaxError: UTF-16 stream does not start with BOM
  • Rami Chowdhury at Aug 20, 2010 at 4:07 pm

    On Fri, Aug 20, 2010 at 21:02, ata.jaf wrote:
    On Aug 19, 11:48?am, Steven D'Aprano <steve-REMOVE-
    T... at cybersource.com.au> wrote:
    On Thu, 19 Aug 2010 01:29:51 -0700, ata.jaf wrote:
    On Aug 17, 11:55?pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython. But I have
    problems with the characters that are not in ASCII. Like some special
    characters in French or Turkish. So I am looking for a way to solve
    this. Like an encoding standard that supports all languages. Or some
    other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text
    is mostly Latin, then just go for UTF-8, if you use other alphabets
    extensively, you might want to consider UTF-16, which might the use a
    little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code
    Do you have a source code encoding line at the start of your script?

    http://www.python.org/dev/peps/pep-0263/
    Yes I have a source code encoding line.
    Here it is:

    # -*- coding: utf_16 -*-

    I am using WxPython.

    And the error that I get about using utf-16 is:\

    Traceback (most recent call last):
    ?File "<stdin>", line 1, in <module>
    ?File "z.py", line 2
    SyntaxError: UTF-16 stream does not start with BOM
    Which encoding are you saving your script in? Very few of the text
    editors I've used save to UTF-16 by default.

    --
    Rami Chowdhury
    "Never assume malice when stupidity will suffice." -- Hanlon's Razor
    408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
  • John Nagle at Aug 20, 2010 at 6:54 pm

    On 8/20/2010 9:07 AM, Rami Chowdhury wrote:
    On Fri, Aug 20, 2010 at 21:02, ata.jafwrote:
    On Aug 19, 11:48 am, Steven D'Aprano<steve-REMOVE-
    T... at cybersource.com.au> wrote:
    On Thu, 19 Aug 2010 01:29:51 -0700, ata.jaf wrote:
    On Aug 17, 11:55 pm, Thomas Jollanswrote:
    Yes I have a source code encoding line.
    Here it is:

    # -*- coding: utf_16 -*-
    Try "utf_8".
    I am using WxPython.

    And the error that I get about using utf-16 is:\

    Traceback (most recent call last):
    File "<stdin>", line 1, in<module>
    File "z.py", line 2
    SyntaxError: UTF-16 stream does not start with BOM
    Which encoding are you saving your script in? Very few of the text
    editors I've used save to UTF-16 by default.
    Most editors that will do Unicode save files as "utf-8".
    Try that.

    John Nagle
  • Martin v. Loewis at Aug 19, 2010 at 8:55 am

    I write a line of strings in the source code and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?".
    Make sure you use Unicode literals in your source code, i.e. u"?".

    HTH,
    Martin
  • Thomas Jollans at Aug 20, 2010 at 7:04 pm

    On Thursday 19 August 2010, it occurred to ata.jaf to exclaim:
    On Aug 17, 11:55 pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython.
    But I have problems with the characters that are not in ASCII. Like
    some special characters in French or Turkish.
    So I am looking for a way to solve this. Like an encoding standard
    that supports all languages. Or some other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text
    is mostly Latin, then just go for UTF-8, if you use other alphabets
    extensively, you might want to consider UTF-16, which might the use a
    little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?". But I see that in GUI this character is replaced
    with another strange characters. I mean it doesn't work.
    And when I try to use UTF-16, I get an syntax error that declares
    "UTF-16 stream does not start with BOM".
    I get the feeling you're not actually using the encoding you say you're using,
    or not telling every program involved what you're doing.

    1. Save the file in the correct encoding. Either tell your text editor to use
    a specific encoding (UTF-8 would be a good choice), or find out what encoding
    your text editor is using and use that encoding during the rest of the
    process.

    2. Tell Python which encoding you're using. The coding: line will do the
    trick, *provided* you don't lie, and the encoding your specify in the file is
    actually the encoding you're using to store the file on disk.

    3. Instruct your GUI library to do the right thing. If you use unicode strings
    (either by using Python 3 or by using the u"K?se" syntax in Python 2), that
    should be enough, otherwise, if you're using byte strings, which you shouldn't
    be doing in this case, you might have to tell the library what you're doing,
    or use the customary encoding. (For GTK+, this is UTF-8. For other libraries,
    it might be Latin-1, or system-dependent)
  • Ata Jafari at Aug 23, 2010 at 1:34 pm

    On Aug 20, 10:04?pm, Thomas Jollans wrote:
    On Thursday 19 August 2010, it occurred to ata.jaf to exclaim:


    On Aug 17, 11:55 pm, Thomas Jollans wrote:
    On Tuesday 17 August 2010, it occurred to ata.jaf to exclaim:
    I am developing a little program in Mac with wxPython.
    But I have problems with the characters that are not in ASCII. Like
    some special characters in French or Turkish.
    So I am looking for a way to solve this. Like an encoding standard
    that supports all languages. Or some other way.
    Anything that supports all of Unicode will do. Like UTF-8. If your text
    is mostly Latin, then just go for UTF-8, if you use other alphabets
    extensively, you might want to consider UTF-16, which might the use a
    little less space.
    OK, I used UTF-8.
    I write a line of strings in the source code and I want my program to
    show that as an output on GUI. And this line of strings includes a
    character like "?". But I see that in GUI this character is replaced
    with another strange characters. I mean it doesn't work.
    And when I try to use UTF-16, I get an syntax error that declares
    "UTF-16 stream does not start with BOM".
    I get the feeling you're not actually using the encoding you say you're using,
    or not telling every program involved what you're doing.

    1. Save the file in the correct encoding. Either tell your text editor to use
    a specific encoding (UTF-8 would be a good choice), or find out what encoding
    your text editor is using and use that encoding during the rest of the
    process.

    2. Tell Python which encoding you're using. The coding: line will do the
    trick, *provided* you don't lie, and the encoding your specify in the file is
    actually the encoding you're using to store the file on disk.

    3. Instruct your GUI library to do the right thing. If you use unicode strings
    (either by using Python 3 or by using the u"K?se" syntax in Python 2), that
    should be enough, otherwise, if you're using byte strings, which you shouldn't
    be doing in this case, you might have to tell the library what you're doing,
    or use the customary encoding. (For GTK+, this is UTF-8. For other libraries,
    it might be Latin-1, or system-dependent)
    Finally I did it.
    I was doing some stupid mistakes.
    Thanks alot.
    Ata
  • Ben Finney at Aug 23, 2010 at 9:38 pm

    Ata Jafari <a.j.romanista at gmail.com> writes:

    Finally I did it.
    I was doing some stupid mistakes.
    Thanks alot.
    For the benefit of future readers of this thread, could you please
    describe what the errors were and how you discovered them? Also what the
    eventual solution was.

    --
    \ ?When I get new information, I change my position. What, sir, |
    `\ do you do with new information?? ?John Maynard Keynes |
    _o__) |
    Ben Finney

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 17, '10 at 8:19p
activeAug 23, '10 at 9:38p
posts11
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase