print u'\u2013' error on console/terminal

Discussion in 'Python' started by robert, Jun 25, 2009.

  1. robert

    robert Guest

    >>> sys.stdout.encoding
    'cp850'
    >>> print u'\u2013'

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python25\Lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
    UnicodeEncodeError: 'charmap' codec can't encode character
    u'\u2013' in position
    0: character maps to <undefined>
    >>> sys.stdout.encoding='xy'

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: readonly attribute



    is there a switch to suppress those encoding errors for standard
    print's on the console - e.g. for getting automatic behavior like
    'replace' :

    >>> print u'a \2013 b'.encode('cp850','replace')

    a ?3 b
    >>>



    or a new filter file class necessary?
     
    robert, Jun 25, 2009
    #1
    1. Advertising

  2. > is there a switch to suppress those encoding errors for standard print's
    > on the console


    No, there is no such switch.

    > or a new filter file class necessary?


    You can wrap sys.stdout with a codecs.StreamWriter, passing "replace"
    as the error handler.

    Regards,
    Martin
     
    Martin v. Löwis, Jun 25, 2009
    #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. thomas Armstrong

    'ascii' codec can't encode character u'\u2013'

    thomas Armstrong, Sep 30, 2005, in forum: Python
    Replies:
    3
    Views:
    4,613
    John J. Lee
    Sep 30, 2005
  2. Fredrik Lundh
    Replies:
    0
    Views:
    1,838
    Fredrik Lundh
    Sep 30, 2005
  3. Replies:
    0
    Views:
    533
  4. gaurav kashyap
    Replies:
    3
    Views:
    6,725
    Paul Boddie
    Oct 31, 2008
  5. Steve
    Replies:
    2
    Views:
    977
    edicionsdigitals.com edicions digitals xarxa socia
    Dec 7, 2010
Loading...

Share This Page