从文本文件中删除特定字符 [英] Removing a specific character from a text file
本文介绍了从文本文件中删除特定字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Python和编码领域的新手,我在做一个很小的项目,却遇到了一个问题:
I'm new to Python and coding generally, and I was doing a tiny project and I'm facing a problem:
44, 1, 6
23, 2, 7
49, 2, 3
53, 2, 1
68, 1, 6
71, 2, 7
我只需要从每行中删除第3和第6个字符,或更确切地说,是从整个文件中删除,"字符.
I just need to remove the 3rd and the 6th character from each line, or more specifically the "," characters from the whole file.
我需要使用我的python代码
and i need to do it using my python code
for line in my_file:
??????????????
有什么可以帮助的,谢谢.
Anything helps, thanks.
推荐答案
您可以替换字符
with open(r'c:\input.txt', 'r') as infile,
open(r'c:\output.txt', 'w') as outfile:
data = infile.read()
data = data.replace(",", "")
outfile.write(data)
这篇关于从文本文件中删除特定字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文