sys.exc_info() different between python 2.5.4 and 2.6.1?

V

Vlastimil Brom

Hi all,
I just noticed a changed behaviour of sys.exc_info() between python
2.5.4 and 2.6.1 and wanted to ask, wheter it was intended, and how to
deal with the new state.

Some code triggers an error while opening a text file (windows 1250 -
with non-ascii characters) wrongly as utf-8,
this gets catched by a bare except clause.
Further the mentioned versions of python differ in handling sys.exc_info()
The following lines:
print sys.exc_info()[1]
print repr(sys.exc_info()[1])
print str(sys.exc_info()[1])
print unicode(sys.exc_info()[1])

result in python 2.5 in:

'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte
UnicodeDecodeError('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte')
'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte
'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte

in python 2.6 it is:
'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte
UnicodeDecodeError('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte')
'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte
('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte')

Which is kind of confusing as my the excepthook function uses the
unicode() form of sys.exc_info()[1]
(The second part "ab\x9acd" is the whole content of the file being
read - which is normally quite a bit longer than this sample...)

Is this the expected behaviour? If so, what might be the reason for
differently outputting str() and unicode()?
How can this be dealt with, are the standard error values somehow
expected to be ascii, so that str() can be used reasonably?

Any hints are much appreciated,
Vlasta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top