Under python2.7, because you want to read the classification name from the database to write to the file, prompt
Traceback (most recent):   " test.py "  in <module>    fp.write ("%d:%s\r\n"%'  ASCII' codec can't encode character u'\uff08' in position 12:ordinal No in range (+)
No fp.write, print with print but normal, how exactly is this coming back?
# !/usr/bin/python # -*-coding:utf-8-*- Import SYS print sys.getdefaultencoding ();
Run the above program tips
Ascii
So, at the head of the program, add
Import sysreload (SYS) sys.setdefaultencoding ('utf-8')
Run again, error message.
To summarize, python2.7 is based on ASCII to handle the character stream, and when the character stream is not within the ASCII range, an exception is thrown (ordinal not in range (128).
Unicodeencodeerror: ' ASCII ' codec can ' t encode character ... The workaround