猿问

Linux上执行python,在文件中写换行符

  1. python 在Linux上执行,版本是2.7

  2. python中的文件操作,写一个换行符,出现了如下错误:

Traceback (most recent call last):  File "parse_new.py", line 130, in <module>    main()  File "parse_new.py", line 102, in main
    f.write("\n")
TypeError: must be unicode, not str


明月笑刀无情
浏览 1006回答 1
1回答

拉风的咖菲猫

python2.7没有默认unicode编码吧 把其转换成unicode编码即可。例如 print(u'hahaha')
随时随地看视频慕课网APP

相关分类

Python
我要回答