我们每天得到巨大的文件大约500 Mb文件,在文件中,我们得到双引号和双引号,它是分号分隔的。
我们如何删除和重新创建文件,以便在python脚本中进行处理,请您帮助我。
如何从文件中删除双引号中的双引号。
来源输入:"000013";"N";"WOUGA";"Y";"N";"N";"EUGENE "A“树林”;“DO”"NOT“”USE“(ACTIVE IN CONCUR);”8“"LONGHORN”中空;
输出:“000013”;“N”;“WOUGA”;“Y”;“N”;“N”;“尤金A森林”;“不使用”(活性在同位);“8长角空心”;
发布于 2022-09-28 20:02:00
可能有一个更优雅的解决方案。但是,看起来您的字符串是用分号分隔的。因此,用分号拆分字符串并遍历这些值对我来说是最简单/最脏的解决方案。
input = """
"000013";"N";"WOUGA";"Y";"N";"N";"EUGENE "A" WOODS";"DO "NOT" USE" (ACTIVE IN CONCUR)";"8 "LONGHORN" HOLLOW";"
""".replace("\n","")
print(input)
split = input.split(";")
output = []
for item in split:
length = len(str(item))
if length > 0 and item != '"': # only append to output row if not null
# print('"' + item.replace('"','') + '"')
formatted_item = str('"' + item.replace('"','') + '"') # replace any inner quotes
output += [formatted_item]
output = ';'.join(output)
output = output + ";"
print(output)

https://stackoverflow.com/questions/73886761
复制相似问题