脚本宝典收集整理的这篇文章主要介绍了Python 文件相关操作,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
文件相关操作
def parse(self, response):
sourec_file = oPEn('aaa.LOG', 'r')
try:
# 读取所有文件
# all_the_text = sourec_file.read()
# PRint(all_the_text)
# 文本文件逐行读取
# for line in sourec_file:
# print(line+'====')
# 读取每行,放入数组
# list_of_all_the_lines = sourec_file.readlines()
# print(list_of_all_the_lines)
# 3.写文件
# 写文本文件
# output = open('data', 'w')
# 写二进制文件
# output = open('data', 'wb')
# 追加写文件
# output = open('data', 'w+')
# 写数据
# file_object = open('thefile.txt', 'w')
# file_object.wrITe(all_the_text)
# file_object.close( )
# 写入多行
# file_object.writelines(list_of_text_strings)
# 注意,调用writelineS写入多行在性能上会比使用write一次性写入要高。
except Exception as e:
raise
else:
pass
finally:
sourec_file.close()
以上是脚本宝典为你收集整理的Python 文件相关操作全部内容,希望文章能够帮你解决Python 文件相关操作所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。