Python第二章公交系统数据读取与处理

2017-07-18  本文已影响0人  SYSinsight
>>> a = open('test.txt','a')
>>> line1 = 'string'
>>> a.write(line1)
>>> 
>>> line2 = u'unicode'
>>> a.write(line2)
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

解决方式

>>> a = codecs.open('test.txt','a','utf-8')
>>> line1 = u'unicode'
>>> a.write(line1)
>>> 

摘自leidianfu的cnblog

上一篇下一篇

猜你喜欢

热点阅读