sys.setdefaultencoding(name)

Discussion in 'Python' started by Askari, Sep 18, 2004.

  1. Askari

    Askari Guest

    Where is the method : "sys.setdefaultencoding(name)"?

    Problem :
    I want change the default encoding because I want put french letter :
    éÉàÀ...etc in widget with no problem! When I use the method ".get" from a
    widget (Text, Entry), the string returned is "fucked"...
    In the Entry widget, the text is (with .insert) "été"
    When I add a "é" at end (with my keyboard), th result is "étéé" OR a
    raised error!

    I find, on net, that I must use "sys.setdefaultencoding(name)".
    I find find this methode in the doc (official) but the
    "setdefaultencoding" name method is not in the sys module!?! (when I print
    "dir(sys)"?! :-(

    Askari
     
    Askari, Sep 18, 2004
    #1
    1. Advertising

  2. Askari

    Harald Massa Guest

    Askari,

    > When I use the method ".get" from a widget (Text, Entry), the string
    > returned is "fucked"...


    That must be a virus or something. Encoding issues normally provide garbled
    strings, but not the word "fucked". Somebody is playing jokes with you.

    > I find, on net, that I must use "sys.setdefaultencoding(name)".


    setdefaultencoding gets removed from sys after execution of site.py /
    sitecustomize.py.

    My solution is to grab site.py, dig up "default encoding" and change from
    imperalistic ASCII to LATIN-1.

    Some told me that avangarde persons also take UTF8.

    Harald
     
    Harald Massa, Sep 18, 2004
    #2
    1. Advertising

  3. Harald Massa wrote:
    > Askari,
    >
    >> When I use the method ".get" from a widget (Text, Entry), the string
    >> returned is "fucked"...

    >
    > That must be a virus or something. Encoding issues normally provide garbled
    > strings, but not the word "fucked". Somebody is playing jokes with you.


    I doubt that the quotes in the OP indicate a literal string.

    Reinhold

    --
    [Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
    jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
    jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
    mitteln inkompatibel. -- Florian Diesch in dcoulm
     
    Reinhold Birkenfeld, Sep 18, 2004
    #3
  4. Askari

    Askari Guest

    Harald Massa <> wrote in
    news:Xns9568A73F4BFF9cpl19ghumspamgourmet@195.20.224.116:

    > My solution is to grab site.py, dig up "default encoding" and change
    > from imperalistic ASCII to LATIN-1.


    euh... I try (the line #2 and #3 in my ".py"):
    """
    import site
    site.encoding = "latin_1"
    """

    but I have this error when I modify a widget (with keyboard) I have this
    error :
    """
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc9 in position 0:
    ordinal not in range(128)
    """

    Why?
    And, I do the good think? (site.encoding = "latin_1")


    Askari
     
    Askari, Sep 19, 2004
    #4
  5. Askari

    Harald Massa Guest

    Askari,

    > """
    > import site
    > site.encoding = "latin_1"
    > """
    >
    > Why?
    > And, I do the good think? (site.encoding = "latin_1")


    No, you do a the bad thing.

    You have to EDIT the site.py within python\lib\site.py

    open it within an editor, find "ASCII" and replace by latin1

    site.encodiging="Latin_1" just adds an attribute NOBODY cares for to a
    module in memory.

    Harald
     
    Harald Massa, Sep 19, 2004
    #5
  6. Askari

    Askari Guest

    Harald Massa <> wrote in
    news:Xns9569F39D2C884cpl19ghumspamgourmet@195.20.224.116:

    > Askari,
    >
    >> """
    >> import site
    >> site.encoding = "latin_1"
    >> """
    >>
    >> Why?
    >> And, I do the good think? (site.encoding = "latin_1")

    >
    > No, you do a the bad thing.
    >
    > You have to EDIT the site.py within python\lib\site.py
    >
    > open it within an editor, find "ASCII" and replace by latin1
    >
    > site.encodiging="Latin_1" just adds an attribute NOBODY cares for to a
    > module in memory.
    >
    > Harald
    >


    It work! :)

    Thanks!
     
    Askari, Sep 20, 2004
    #6
    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. christof hoeke

    xml processing and sys.setdefaultencoding

    christof hoeke, Jul 20, 2003, in forum: Python
    Replies:
    4
    Views:
    831
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Jul 21, 2003
  2. Robin Becker

    sys.setdefaultencoding

    Robin Becker, Aug 28, 2007, in forum: Python
    Replies:
    1
    Views:
    379
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Aug 28, 2007
  3. smalltalk

    setdefaultencoding error

    smalltalk, Dec 8, 2007, in forum: Python
    Replies:
    2
    Views:
    1,098
    smalltalk
    Dec 10, 2007
  4. crow
    Replies:
    5
    Views:
    701
    Terry Reedy
    Jul 9, 2010
  5. moerchendiser2k3

    Is setdefaultencoding bad?

    moerchendiser2k3, Feb 23, 2011, in forum: Python
    Replies:
    4
    Views:
    301
    Nobody
    Feb 24, 2011
Loading...

Share This Page