-3

here is my question :

    if not line.startswith('  File "<frozen importlib._bootstrap'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 45: ordinal not in range(128)

I've tried the method :

import sys  
reload(sys)  
sys.setdefaultencoding('utf8')

but it seems that it didn't work on the version 2.7

Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
lv wanyou
  • 1
  • 1

1 Answers1

0

You would benefit from learning about string encoding.
That said, there's something in Python 2.7 which solves these problems most of the time.

from __future__ import unicode_literals

This has to be the first statement in your Python module. It will change the data types of all strings in the module to Unicode.

Be careful and read about pros and cons.
Generally speaking, you will be fine if you are starting a new project, but introducing this change in existing (especially big) project can be a hard and time consuming task.

One more thing - when starting a new Python project now, you should really consider doing it in Python 3. The end of life of for Python 2.7 has been moved to 2020 but it's just 2 years from now. Python 3 has many interesting features and improvements. What you will find important is that str is Unicode in Python 3 - it means that encoding problems don't happen so often.

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46