原数据
每行末尾都有额外的“\”
Python代码
# 读取文件
file = open("./datasets/phishingURIs_00.csv", "r")
# lines列表存储每一行的内容
lines = []
for i in file:
# 遍历每一行内容进行存储
lines.append(i)
# 读取完毕
file.close()
# 用于存储处理后的每一行内容
new = []
for line in lines:
# 若该行以 \ 结尾
if line[:-1].endswith("\\"):
# 去除该符号
tmp = line[:-1].rstrip("\\")
# 结尾加上换行符并存储
new.append(tmp + "\n")
# 若该行以 \ 结尾
elif line[:-1].endswith("}"):
# 去除该符号
tmp = line[:-1].rstrip("}")
# 结尾加上换行符并存储
new.append(tmp + "\n")
else:
# 若不以分号结尾,则直接存储
new.append(line)
# 写入模式
file_write_object = open("./datasets/phishingURIs_01.csv", "w")
for var in new:
file_write_object.writelines(var)
file_write_object.close()
结果