我有一个文本文件,我想删除标点符号并将其另存为新文件,但它没有删除任何内容,为什么?
代码:
def punctuation(string):
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
for x in string.lower():
if x in punctuations:
string = string.replace(x, "")
# Print string without punctuation
print(string)
file = open('ir500.txt', 'r+')
file_no_punc = (file.read())
punctuation(l)
with open('ir500_no_punc.txt', 'w') as file:
file.write(file_no_punc)
删除任何标点符号为什么?