python - 删除字符串中的第一个元素时创建的空文件
问题描述
我的代码是 -
import os
currentdir = "........."
resultdir="............."
for root, dirs, files in os.walk(currentdir):
for name in files:
outfile1 = open(resultdir + "/" + name, "w+")
#outfile1 = open(resultdir + "/" + name, "w+")
print(name)
outfile2 = open(root+"/"+name,'r')
line = outfile2.readline()
while line:
#print(line)
if line[0]!="\"":
print(line)
outfile1.write(line)
outfile1.write("\n")
line = outfile2.readline()
outfile2.close()
outfile1.close()
我正在尝试从目录中读取每个文件,并且在每个文件中我试图省略开头有“”的行并将这些更正的文件保存在新目录中。但是我在新目录中得到空文件。
解决方案
推荐阅读
- c# - SqlException:无法将值 NULL 插入列“UserDetail_Id”、表“dbo.Users”;列不允许空值。插入失败
- git - 从 Bitbucket 开始 - 如何移动我的本地开发文件夹并保留历史记录?
- javascript - JQuery如何正确设置滑块效果
- elixir - Elixir-Phoenix:在测试中禁用 Hammer 的速率限制
- mongodb - 在 express API 中获取字符串以传递给 mongodb 查找函数
- c# - 是否有 C# 代码直接在对象引用上调用 `brtrue`/`brfalse` 指令的空值检查功能?
- java - 为什么java静态变量不更新?
- python - 如何在 Pygame 中画一个半透明的圆圈?
- javascript - JavaScript - window.scroll({ behavior: 'smooth' }) 在 Safari 中不起作用
- node.js - util方法的firebase代码组织