sys.setdefaultencoding

Discussion in 'Python' started by Robin Becker, Aug 28, 2007.

  1. Robin Becker

    Robin Becker Guest

    Can someone explain the rationale of making the default encoding a sitewide setting?

    I could live with the the default being set on a per process basis, but it
    baffles me why even that possibility is taken away as site.py removes
    sys.setdefaultencoding.

    Is there a way to allow the process to specify that unicode-->str should use
    'utf8' rather than 'ascii' in all non-specific cases?
    --
    Robin Becker
     
    Robin Becker, Aug 28, 2007
    #1
    1. Advertising

  2. > Is there a way to allow the process to specify that unicode-->str should
    > use 'utf8' rather than 'ascii' in all non-specific cases?


    No. Things might break if you change the default encoding to anything
    but ASCII, and more so if you do that "at runtime". For example,
    dictionaries with Unicode keys may stop working, and the cached
    byte-oriented version of a Unicode string may become incorrect.

    In general, programs and libraries should not rely on the default
    encoding for anything. Instead, they should convert explicitly,
    either from an explicitly specified encoding, or one derived from
    the context. Experience has shown that this is possible in nearly
    every case (and in all cases if an appropriate refactoring is made).

    Regards,
    Martin
     
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Aug 28, 2007
    #2
    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. Askari

    sys.setdefaultencoding(name)

    Askari, Sep 18, 2004, in forum: Python
    Replies:
    5
    Views:
    5,333
    Askari
    Sep 20, 2004
  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