我需要从文本文件中删除punc。
文本文件是这样的
ffff, hhhh, & tommorw home,
Have you from gone?
我在努力
punc=(",./;'?&-")
f = open('file.txt', 'r')
for line in f:
strp=line.replace(punc,"")
print(strp)
我需要输出:
ffff hhhh tommorw home
Have you from gone
这将返回每一行,但punc仍然存在>;可能需要一些帮助。谢谢
Tags:
使用
str.translate
从字符串中删除字符。在Python 2.x中:
在Python 3中:
或者,可以使用
str.maketrans
来构建transtable
:相关问题 更多 >
编程相关推荐