python - 打开和关闭大量文件后,脚本python无缘无故停止运行
问题描述
我需要打开几个文件,逐行读取并归档。但是,我必须分析大量的行。在大约 240k 行之后,脚本似乎无缘无故地暂停了。
编码:
for folder in os.listdir("Data"):
for subfolder in os.listdir("Data/"+folder):
with open("Data/"+folder+'/'+subfolder, "r", encoding='utf8', errors='ignore') as f:
for line in f:
path = "Data/" + line[0] + "/"
if not os.path.exists(path):
os.makedirs(path)
with open(path + line[1] +".txt", "a", encoding="utf-8", errors="ignore") as f1:
f1.writelines(line)
tested += 1
print("folder: "+folder+", subfolder: "+subfolder+", tested: "+str(tested))
控制台只是停止打印而不停止脚本
解决方案
推荐阅读
- node.js - 未从 Slack Slash Commands API 接收任何数据
- angular - Angular 7 http.post 正在向 yii2 API 发送 null
- jenkins - 将当前构建的工件复制到服务器位置的 Jenkins 管道脚本
- excel - 打开现有 Excel 文件并通过 MS Project 在该文件中运行宏
- arrays - 为什么 React SetState 没有按预期工作?
- java - Java Android Google 地图更改缩放控件位置并将相机设置为标记
- sql-server - 如何从 SQL Server 数据库生成 XML 文件
- python - 面对python pip的麻烦
- javascript - 在节点 js 中将 Facebook Messenger 附件图像类型转换为 base64
- android - 如何修复无法解决:com.android.support:design:28.0.3