with open('data.txt','w') as f: #设置文件对象 w是重新写,原来的会被抹掉,a+是在原来的基础上写 str0=u"写文件\n" #写中文要在字符串签名加个u来表示Unicode str1="I am good kid who like study" f.write(str0) f.write(str1) 文件内容: 写文件I am good kid who like study 注:人生苦短,我用python
# -*- coding: utf-8 -*- # Scrapy settings for maitian project # # For simplicity, this file contains only settings considered important or # commonly used. You can find more settings consulting the documentation: # # https://doc.scrapy.org/en/latest/