为了解决此问题
解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
从而在代码中使用了reload(sys)
但在此句过后,print语句无法正常输出内容,有办法解决吗?
>>> print 123
123
>>> print sys.getdefaultencoding()
cp936
>>> reload(sys)
>>> print sys.getdefaultencoding()
>>> print 123
>>>
You should be running it under idle? It cannot print because the stdout of idle is not the default stdout, so all the output to stdout after reload(sys) cannot be seen. You can consider the following code to change stdout back after reload(sys)
Similarly, we also need to do the same processing for stdin and stderr