Hello everyone!
When I was building a learning website recently, when I was using the logging diary, I found that the generated logging diary was garbled. Import the sys module, and then determine the encoding format! I thought it was troublesome to import modules, so I didn't use it. It is the following lines of code:
import logging
import sys
reload(sys)
sys.setdefaultencoding('gbk')
The following is a solution I found, I hope it can help you!
Because there are two ways of log output (as far as I know):
1. Output to the console
2. Save to file
I just opened the garbled characters after saving the file
Below is a screenshot of my garbled code!
Then, I found in the upper right corner of pycharm
Then I click Reload in "GBK"
No more garbled characters! ! Solved successfully!
Well, that's all for today's sharing, if there is something unclear or I wrote something wrong, please give me your advice!
Private message, comment me! ! ! ! ! !