making 'utf-8' default codec

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nikola Skoric

    making 'utf-8' default codec

    Hi there,

    Is there a way of making 'utf-8' default codec for the whole program, so
    I don't have to do .encode('utf-8') every time I print out a string?

    --
    "Now the storm has passed over me
    I'm left to drift on a dead calm sea
    And watch her forever through the cracks in the beams
    Nailed across the doorways of the bedrooms of my dreams"
  • Jarek Zgoda

    #2
    Re: making 'utf-8' default codec

    Nikola Skoric napisa³(a):
    [color=blue]
    > Is there a way of making 'utf-8' default codec for the whole program, so
    > I don't have to do .encode('utf-8') every time I print out a string?[/color]

    Bad idea. You may accidentally break some libraries that depend on ASCII
    being default & standard.

    --
    Jarek Zgoda

    Comment

    • Scott David Daniels

      #3
      Re: making 'utf-8' default codec

      Nikola Skoric wrote:[color=blue]
      > Is there a way of making 'utf-8' default codec for the whole program, so
      > I don't have to do .encode('utf-8') every time I print out a string?[/color]

      Explicit is better than implicit (so setting up a default codec is
      considered bad practice). However, you could wrap an output destination
      with an encoder and get the effect you want.

      import sys, codecs
      sys.stdout, _held = (codecs.getwrit er('utf-8')(sys.stdout) ,
      sys.stdout)

      --Scott David Daniels
      scott.daniels@a cm.org

      Comment

      • Jorge Godoy

        #4
        Re: making 'utf-8' default codec

        Jarek Zgoda <jzgoda@o2.usun .pl> writes:
        [color=blue]
        > Bad idea. You may accidentally break some libraries that depend on ASCII
        > being default & standard.[/color]

        And what would those produce as output when fed with unicode data? How would
        they handle this input? IMVHO nothing should rely on having a standard
        charset as input. If it is required, then the library should set it up by
        itself: explicit is better than implicit.

        --
        Jorge Godoy <godoy@ieee.org >

        "Quidquid latine dictum sit, altum sonatur."
        - Qualquer coisa dita em latim soa profundo.
        - Anything said in Latin sounds smart.

        Comment

        • Jarek Zgoda

          #5
          Re: making 'utf-8' default codec

          Jorge Godoy napisa³(a):
          [color=blue][color=green]
          >>Bad idea. You may accidentally break some libraries that depend on ASCII
          >>being default & standard.[/color]
          >
          > And what would those produce as output when fed with unicode data? How would
          > they handle this input? IMVHO nothing should rely on having a standard
          > charset as input. If it is required, then the library should set it up by
          > itself: explicit is better than implicit.[/color]

          Besides that, changing default encoding will make program nearly
          absolutely unportable as Python by default installs nearly everywhere
          with ASCII as default encoding (with iSeries being the only exception
          known to me).

          --
          Jarek Zgoda

          Comment

          Working...