Re: About print exception message

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: About print exception message

    On Thu, 9 Oct 2008 06:37:04 -0700 (PDT), WaterWalk <toolmaster@163 .comwrote:
    >Until Python 2.5, the exception object still uses ansi string. Thus,
    >in the following example:
    >
    >f = open(u"\u6d4b.l og")
    >
    >Suppose the file to open does not exist, the output message of the
    >exception maybe like:
    >[Errno 2] No such file or directory: u'\u6d4b.log'
    >
    >This is not a clear message.
    I disagree. But if you'd rather see the character (or a replacement character,
    or possibly an empty box, depending on your environment's text rendering
    capabilities), it's a bit easier than writing that big function:
    >>try: open(u'\N{WHITE SMILING FACE}')
    .... except IOError, e: print str(e).decode(' unicode-escape')
    ....
    [Errno 2] No such file or directory: u'☺'
    >>
    Jean-Paul
  • WaterWalk

    #2
    Re: About print exception message

    On Oct 9, 9:46 pm, Jean-Paul Calderone <exar...@divmod .comwrote:
    On Thu, 9 Oct 2008 06:37:04 -0700 (PDT), WaterWalk <toolmas...@163 .comwrote:
    Until Python 2.5, the exception object still uses ansi string.  Thus,
    in the following example:
    >
    f = open(u"\u6d4b.l og")
    >
    Suppose the file to open does not exist, the output message of the
    exception maybe like:
    [Errno 2] No such file or directory: u'\u6d4b.log'
    >
    This is not a clear message.
    >
    I disagree.  But if you'd rather see the character (or a replacementchar acter,
    or possibly an empty box, depending on your environment's text rendering
    capabilities), it's a bit easier than writing that big function:
    >
    >try: open(u'\N{WHITE SMILING FACE}')
    >
    ... except IOError, e: print str(e).decode(' unicode-escape')
    ...
    [Errno 2] No such file or directory: u'☺'
    >
    Yes, this is a more concise solution. Thank you.

    Comment

    Working...